Created
March 9, 2018 05:48
-
-
Save antklim/2066c2b40e73d9ef2722115293ffc2ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
LaunchConfiguration: | |
Type: AWS::AutoScaling::LaunchConfiguration | |
Properties: | |
ImageId: !FindInMap [AWSRegionToAMI, !Ref "AWS::Region", AMI] | |
InstanceType: t2.micro | |
SecurityGroups: | |
- !Ref EC2HostSecurityGroup | |
IamInstanceProfile: !Ref InstanceProfile | |
UserData: | |
"Fn::Base64": !Sub | | |
#!/bin/bash | |
yum install -y aws-cfn-bootstrap | |
/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration | |
/opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup | |
Metadata: | |
AWS::CloudFormation::Init: | |
config: | |
users: | |
simpleapi: | |
homeDir: /etc/simpleapi | |
commands: | |
'1 - Create home directory for simpleapi': | |
command: !Sub | | |
mkdir -p /etc/simpleapi | |
chown -R simpleapi:simpleapi /etc/simpleapi | |
'2 - Install the CloudWatch logs agent': | |
command: !Sub | | |
cd /tmp | |
wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py | |
python awslogs-agent-setup.py -n -r ${AWS::Region} -c /tmp/cwlogs.conf || error_exit 'Failed to run CloudWatch Logs agent setup' | |
'3 - Install GIT': | |
command: !Sub | | |
yum -y install git | |
'3 - Install NodeJS': | |
command: !Sub | | |
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash - | |
yum -y install nodejs | |
'4 - Download SimpleAPI': | |
command: !Sub | | |
cd /etc/simpleapi | |
git clone --depth=1 --branch=master ${SimpleAPIRepoUrl} . | |
rm -rf !$/.git | |
'5 - Install SimpleAPI dependencies': | |
command: !Sub | | |
cd /etc/simpleapi | |
npm install --production | |
'6 - Launch SimpleAPI': | |
command: !Sub | | |
cd /etc/simpleapi | |
su -p -c "npm start" -s /bin/sh simpleapi | |
files: | |
'/tmp/cwlogs.conf': | |
content: !Sub | | |
[general] | |
state_file= /var/awslogs/agent-state | |
[simpleapi-stdout] | |
file = /etc/kg/simpleapi/out.log | |
log_group_name = /${Namespace}/${Environment} | |
log_stream_name = stdout | |
datetime_format = %Y-%m-%d %H:%M:%S.%f | |
[simpleapi-stderr] | |
file = /etc/kg/simpleapi/err.log | |
log_group_name = /${Namespace}/${Environment} | |
log_stream_name = stderr | |
datetime_format = %Y-%m-%d %H:%M:%S.%f | |
[cfn-init] | |
file = /var/log/cfn-init.log | |
log_group_name = /${Namespace}/${Environment} | |
log_stream_name = cfn-init | |
datetime_format = %Y-%m-%d %H:%M:%S.%f | |
[messages] | |
file = /var/log/messages | |
log_group_name = /${Namespace}/${Environment} | |
log_stream_name = messages | |
datetime_format = %b %m %H:%M:%S | |
[secure] | |
file = /var/log/secure | |
log_group_name = /${Namespace}/${Environment} | |
log_stream_name = secure | |
datetime_format = %b %m %H:%M:%S |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment