Created
October 15, 2019 22:08
-
-
Save fenxiong/8ec9529bb1c23e510bc4dea0d3ed9955 to your computer and use it in GitHub Desktop.
testautocscalingtags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Parameters": { | |
"TestName": { | |
"Type" : "String" | |
}, | |
"InstanceType" : { | |
"Type" : "String", | |
"Default" : "m4.xlarge" | |
}, | |
"ImageId":{ | |
"Type" : "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>", | |
"Default": "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id" | |
}, | |
"KeyPairName":{ | |
"Type" : "String", | |
"Default": "xxx" | |
}, | |
"SubnetId":{ | |
"Type" : "String", | |
"Default": "subnet-xxx" | |
}, | |
"SecurityGroupId":{ | |
"Type" : "String", | |
"Default": "sg-xxx" | |
}, | |
"InstanceProfile":{ | |
"Type" : "String", | |
"Default": "ecsEC2Role" | |
}, | |
"InstanceCount": { | |
"Type": "String", | |
"Default": "3" | |
} | |
}, | |
"Resources": | |
{ | |
"MyCluster": { | |
"Type": "AWS::ECS::Cluster", | |
"Properties":{ | |
"ClusterName": {"Ref": "TestName"} | |
} | |
}, | |
"MyLaunchConfiguration": { | |
"Type": "AWS::AutoScaling::LaunchConfiguration", | |
"Properties": { | |
"AssociatePublicIpAddress": true, | |
"ImageId" : {"Ref" : "ImageId"}, | |
"InstanceType": {"Ref" : "InstanceType"}, | |
"SecurityGroups" : [{"Ref" : "SecurityGroupId"}], | |
"KeyName": {"Ref":"KeyPairName"}, | |
"IamInstanceProfile": {"Ref": "InstanceProfile"}, | |
"UserData" : { | |
"Fn::Base64" : { | |
"Fn::Join" : ["\n", [ | |
"#!/bin/bash", | |
{ | |
"Fn::Sub": [ | |
"echo ECS_CLUSTER=${ClusterName} >> /etc/ecs/ecs.config", | |
{"ClusterName": {"Ref": "TestName"}} | |
] | |
}, | |
"echo ECS_LOGLEVEL=debug >> /etc/ecs/ecs.config", | |
"echo ECS_CONTAINER_INSTANCE_PROPAGATE_TAGS_FROM=ec2_instance >> /etc/ecs/ecs.config", | |
"echo 'export GOPATH=/home/ec2-user/workplace/go' >> /home/ec2-user/.bash_profile", | |
"echo 'export PATH=$GOPATH/bin:$PATH' >> /home/ec2-user/.bash_profile", | |
"echo 'alias up=\"sudo systemctl start ecs\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias down=\"sudo systemctl stop ecs\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias rmdata=\"sudo rm -r /var/lib/ecs/data/*\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias rmlogs=\"sudo rm /var/log/ecs/*\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias rlogs=\"sudo vim /var/log/ecs/ecs-agent*\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias wdp=\"watch docker ps\"' >> /home/ec2-user/.bash_profile", | |
"echo 'alias go2agent=\"cd /home/ec2-user/workplace/go/src/github.com/aws/amazon-ecs-agent\"' >> /home/ec2-user/.bash_profile", | |
"source /home/ec2-user/.bash_profile", | |
"yum install -y go git vim aws-cli jq lsof", | |
"su ec2-user -c 'mkdir -p /home/ec2-user/workplace/go/src/github.com/aws/amazon-ecs-agent'", | |
"su ec2-user -c 'git clone https://github.com/fenxiong/amazon-ecs-agent /home/ec2-user/workplace/go/src/github.com/aws/amazon-ecs-agent'" | |
]] | |
} | |
} | |
} | |
}, | |
"MyAutoScalingGroup": { | |
"Type": "AWS::AutoScaling::AutoScalingGroup", | |
"Properties": { | |
"AutoScalingGroupName": {"Ref": "TestName"}, | |
"LaunchConfigurationName": {"Ref": "MyLaunchConfiguration"}, | |
"VPCZoneIdentifier": [{"Ref": "SubnetId"}], | |
"DesiredCapacity": {"Ref": "InstanceCount"}, | |
"MinSize": {"Ref": "InstanceCount"}, | |
"MaxSize": {"Ref": "InstanceCount"}, | |
"Tags": [ | |
{ | |
"Key": "Name", | |
"Value": {"Ref": "TestName"}, | |
"PropagateAtLaunch": true | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment