Jenkins has a great plugin for deploying Elastic Beanstalk apps, but nothing as slick to deploy to OpsWorks. But fear not. The AWS CLI makes it pretty easy once you extract your OpsWorks stack ID and app ID. Below is a simple script to deploy which requires:

  1. The AWS CLI tool (pip install awscli)
  2. AWS credentials specified in your environment or for your jenkins user
  3. A few environment variables to be set in order to get you built:

    1. APPNAME
    2. ENVIRONMENT (dev, staging, prod, etc.)
    3. S3_BUCKET_NAME
    4. OPSWORKS_APP_ID
    5. OPSWORKS_STACK_ID

This zips up your application by tier and build number then triggers a deployment in Opsworks:

export ARCHIVE_FILENAME=${APPNAME}.${ENVIRONMENT}.${BUILD_ID}.zip
export S3_PATH=s3://${S3_BUCKET_NAME}/${APPNAME}/${ENVIRONMENT}/
export S3_URL=https://s3.amazonaws.com/${S3_BUCKET_NAME}/${APPNAME}/${ENVIRONMENT}/${ARCHIVE_FILENAME}
zip $ARCHIVE_FILENAME -r dist/*
aws s3 cp $ARCHIVE_FILENAME $S3_PATH

aws opsworks update-app --app-id $OPSWORKS_APP_ID --app-source Url=$S3_URL
aws opsworks create-deployment --stack-id $OPSWORKS_STACK_ID --app-id $OPSWORKS_APP_ID --command '{"Name": "deploy"}'

Happy deploying!