Skip to content

Instantly share code, notes, and snippets.

@panbanda
Last active July 15, 2016 17:29
Show Gist options
  • Save panbanda/31d5a0372f1e799a4eb1 to your computer and use it in GitHub Desktop.
Save panbanda/31d5a0372f1e799a4eb1 to your computer and use it in GitHub Desktop.
OpsWorks deploy script for multiple instances in a stack. Meant to work with Codeship.
# Install the aws cli client
pip install awscli
# List instances for a particular stack
OPSWORKS_STACK_ID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
OPSWORKS_APP_ID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
OPSWORKS_INSTANCE_LAYER_ID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
# Deploy the stack and app to instances found above
# This endpoint is only available in `us-east-1` even though
# your application may be hosted in another zone.
#
# Instance state codes can be found here:
# http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html
aws opsworks create-deployment --region=us-east-1 --stack-id="$OPSWORKS_STACK_ID" --app-id="$OPSWORKS_APP_ID" --instance-ids "[$(aws opsworks describe-instances --region us-east-1 --layer-id $OPSWORKS_INSTANCE_LAYER_ID --query 'Instances[].[InstanceId]' | grep -o '"[^"]\+"' | paste -s -d "," - )]" --command='{"Name": "deploy"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment