Skip to content

Instantly share code, notes, and snippets.

@mario21ic
Created May 24, 2017 17:44
Show Gist options
  • Save mario21ic/9973ad73b3647cfa28e4a191e60b4e56 to your computer and use it in GitHub Desktop.
Save mario21ic/9973ad73b3647cfa28e4a191e60b4e56 to your computer and use it in GitHub Desktop.
Script to use in user data to aws ec2
#!/bin/bash
BUCKET="mybucket.deploy"
ENVIRONMENT="dev"
LATEST="/tmp/latest.zip"
APP_DIR="/var/www/web"
latest=$(aws s3 ls s3://$BUCKET/$ENVIRONMENT/ --recursive | sort | tail -n 1 | awk '{print $4}')
aws s3 cp s3://$BUCKET/$latest $LATEST
sudo mkdir -p $APP_DIR && unzip -qo $LATEST -d $APP_DIR
rm -f $LATEST
chown ec2-user:ec2-user -R $APP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment