Last active
December 10, 2018 05:02
-
-
Save seventhskye/27e2bb52cf6ffd96378c to your computer and use it in GitHub Desktop.
Userdata script to download and execute a set of bash scripts from Amazon S3. Useful if you wanted to have a predefined set of scripts to share amongst EC2 instance, e.g. userdata.
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
#!/bin/bash -x | |
# The bucket containing the userdata.d | |
export USERDATAD_BUCKET=userdata.example.com | |
# Required to set the endpoint of the aws-cli | |
export AWS_DEFAULT_REGION=eu-west-1 | |
# Install Prerequisites | |
yum install -y aws-cli | |
# Download all .sh scripts from the bucket and pipe to bash | |
SCRIPTS=$(aws s3 ls s3://$USERDATAD_BUCKET/userdata.d/ | awk '{ print $4 }') | |
for S in $SCRIPTS; do | |
aws --color=off s3 cp --quiet s3://$USERDATAD_BUCKET/userdata.d/$S - | bash -s | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment