forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webserver.js
37 lines (32 loc) · 1.09 KB
/
webserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");
// Get the id for the latest Amazon Linux AMI
let ami = aws.ec2.getAmi({
filters: [
{ name: "name", values: ["amzn-ami-hvm-*-x86_64-ebs"] },
],
owners: ["137112412989"], // Amazon
mostRecent: true,
}, { async: true }).then(result => result.id);
// create a new security group for port 80
let group = new aws.ec2.SecurityGroup("web-secgrp", {
description: "Enable HTTP access",
ingress: [
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
],
});
// (optional) create a simple web server using the startup script for the instance
let userData =
`#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`;
exports.createInstance = function (name, size) {
return new aws.ec2.Instance(name, {
tags: { "Name": name },
instanceType: size,
vpcSecurityGroupIds: [ group.id ], // reference the group object above
ami: ami,
userData: userData // start a simple web server
});
}