Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sk-t3ch/869b07d983e3d900c268658717e8b6fa to your computer and use it in GitHub Desktop.
Save sk-t3ch/869b07d983e3d900c268658717e8b6fa to your computer and use it in GitHub Desktop.
Hello World Cluster CloudFormation - Launch Template
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
amazon-ssm-agent: []
commands:
00_amazon_ssm_agent_start:
command: systemctl start amazon-ssm-agent
files:
/etc/cfn/cfn-hup.conf:
content: |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
interval=1
mode: "000400"
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.LaunchTemplate.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init --verbose --stack=${AWS::StackName} --region=${AWS::Region} --resource=LaunchTemplate
runas=root
services:
sysvinit:
cfn-hup:
enabled: true
ensureRunning: true
files:
- "/etc/cfn/cfn-hup.conf"
- "/etc/cfn/hooks.d/cfn-auto-reloader.conf"
Properties:
LaunchTemplateData:
CreditSpecification:
CpuCredits: Unlimited
ImageId: 'ami-09266271a2521d06f' #ecs optimised image for eu-west-1
InstanceType: t2.micro
IamInstanceProfile:
Arn: !GetAtt InstanceProfile.Arn
Monitoring:
Enabled: true
SecurityGroupIds:
- !Ref EC2SecurityGroup
UserData:
Fn::Base64:
Fn::Sub:
- |
#!/bin/bash -xe
yum update -y
yum install -y aws-cli aws-cfn-bootstrap
echo ECS_CLUSTER=${Cluster} >> /etc/ecs/ecs.config
echo ECS_ENABLE_SPOT_INSTANCE_DRAINING=1 >> /etc/ecs/ecs.config
# -r needs to be name of the LaunchTemplate resource. In this case: LaunchTemplate
/opt/aws/bin/cfn-init -v -s ${AWS::StackName} -r LaunchTemplate --region ${AWS::Region}
- { Cluster: !ImportValue ECSCluster }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment