Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bacarybruno/45b1d6a8759ed514e06e6850591b33f4 to your computer and use it in GitHub Desktop.
Save bacarybruno/45b1d6a8759ed514e06e6850591b33f4 to your computer and use it in GitHub Desktop.
Resources:
NodeSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: Enable HTTP access via port 3000
SecurityGroupIngress:
-
IpProtocol: tcp
FromPort: 3000
ToPort: 3000
CidrIp: 0.0.0.0/0
MyFirstCloudFormationInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-1a
ImageId: ami-a4c7edb2
SecurityGroups:
- !Ref NodeSecurityGroup
InstanceType: t2.micro
UserData:
Fn::Base64: !Sub |
#!/bin/bash
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum update -y
yum install -y nodejs
mkdir node
chmod 777 node
cd node
touch index.js
chmod 777 index.js
echo "const http = require('http');const server=http.createServer(function(request, response){response.setHeader('Content-Type', 'application/json'); response.end(JSON.stringify({message: 'Hello World', date: new Date(), host: '$(hostname -f)' }));});server.listen(3000);console.log('Server is listening on post 3000');" > index.js
node index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment