-
-
Save boostrack/b2c8e0c4290f0b1e3f112d683e1ac8ec to your computer and use it in GitHub Desktop.
Revisions
-
daviddyball revised this gist
Jan 27, 2015 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,9 @@ # # Ensure we have required tools /usr/bin/cloud-init-per once apt-update apt-get update /usr/bin/cloud-init-per once bootstrap-deps1 apt-get install python-pip jq -y /usr/bin/cloud-init-per once bootstrap-deps2 pip install awscli botocore boto # Gather metadata about instance (e.g. Role + Environment) INSTANCE_ID=$(ec2metadata --instance-id) @@ -23,6 +23,6 @@ ROLE=$(echo "$TAGS" |grep Role |awk '{print $3}') ENVIRONMENT=$(echo "$TAGS" | grep Environment|awk '{print $3}') # Pull and run role-specific bootstrap script /usr/bin/cloud-init-per always bootstrap-pull aws s3 cp s3://my-configs/${ENVIRONMENT}/${ROLE}/bootstrap.sh /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh /usr/bin/cloud-init-per always bootstrap-chmod chmod +x /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh /usr/bin/cloud-init-per once bootstrap-run /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh -
daviddyball created this gist
Jan 27, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ { "Statement": [ { "Sid": "EC2DescribeInstances", "Effect": "Allow", "Action": [ "ec2:DescribeInstances", "ec2:DescribeTags" ], "Resource": [ "*" ] }, { "Sid": "S3BucketAccess", "Effect": "Allow", "Action": [ "s3:Get*", "s3:List*" ], "Resource": [ "arn:aws:s3:::my-configs", "arn:aws:s3:::my-configs/*" ] } ] } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/bin/bash # Name: s3://my-configs/user-data.txt # Description: Generic EC2 User-Data File # Purpose: Shim script to pull bootstrap script for the server based on the # Role + Environment tags stored against the EC2 Instance # # Tags Used: # - Environment = Runtime Environment for this server (live/staging/preview) # - Role = The role for this particular server # (e.g. webserver, database, imaging) # # Ensure we have required tools /usr/bin/cloud-init-per once apt-get update /usr/bin/cloud-init-per once apt-get install python-pip jq -y /usr/bin/cloud-init-per once pip install awscli botocore boto # Gather metadata about instance (e.g. Role + Environment) INSTANCE_ID=$(ec2metadata --instance-id) REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}') TAGS=$(aws ec2 describe-instances --instance-id $INSTANCE_ID --region $REGION --output text| grep TAGS) ROLE=$(echo "$TAGS" |grep Role |awk '{print $3}') ENVIRONMENT=$(echo "$TAGS" | grep Environment|awk '{print $3}') # Pull and run role-specific bootstrap script /usr/bin/cloud-init-per always aws s3 cp s3://my-configs/${ENVIRONMENT}/${ROLE}/bootstrap.sh /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh /usr/bin/cloud-init-per always chmod +x /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh /usr/bin/cloud-init-per once /root/${ENVIRONMENT}_${ROLE}_bootstrap.sh