Skip to content

Instantly share code, notes, and snippets.

@RohitRox
Last active September 20, 2018 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitRox/1a5a3c771b32d5c6f22ad5f08b0504bd to your computer and use it in GitHub Desktop.
Save RohitRox/1a5a3c771b32d5c6f22ad5f08b0504bd to your computer and use it in GitHub Desktop.
Hello World Cloudformation Template
AWSTemplateFormatVersion: 2010-09-09
Description: Deploys a basic httpd hello world app in an EC2 instance, create and attach a security group for the instance
Mappings:
Infra:
Vpcs:
Main: vpc-xxxx
Subnets:
Public:
- subnet-xxxx
- subnet-xxxx
Resources:
# Security Group
AppSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: webapp-hello-security-group
GroupDescription: Web App Security Group, HTTP traffic in, all traffic out, SSH enabled
VpcId: !FindInMap [Infra, Vpcs, Main]
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
IpProtocol: tcp
ToPort: 80
FromPort: 80
- CidrIp: 0.0.0.0/0
IpProtocol: tcp
ToPort: 22
FromPort: 22
# App Instance
App:
Type: AWS::EC2::Instance
Properties:
# Hello Aws Community AMI
ImageId: ami-8b5bb6e8
InstanceType: t2.micro
KeyName: ec2-key-name
SubnetId: !Select [ 0, !FindInMap [Infra, Subnets, Public] ]
SecurityGroupIds:
- !Ref AppSecurityGroup
Tags:
- Key: Environment
Value: test
- Key: Role
Value: web
Outputs:
App:
Description: App Instance
Value: !Ref App
AppUrl:
Description: App Endpoint
Value: !GetAtt App.PublicDnsName
@RohitRox
Copy link
Author

RohitRox commented Sep 20, 2018

$ aws cloudformation create-stack --stack-name MyHelloWorld --profile aws-profile-name // create stack
$ aws cloudformation update-stack --stack-name MyHelloWorld --profile aws-profile-name // update stack
$ aws cloudformation delete-stack --stack-name MyHelloWorld --profile aws-profile-name // delete stack
$ aws cloudformation describe-stack-events --stack-name MyHelloWorld --profile aws-profile-name // view stack event logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment