Skip to content

Instantly share code, notes, and snippets.

@retgef
Forked from kgorskowski/create_deployment.sh
Created June 29, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retgef/89410db19919905edd5d59e4a5115118 to your computer and use it in GitHub Desktop.
Save retgef/89410db19919905edd5d59e4a5115118 to your computer and use it in GitHub Desktop.
recreate latest successful codedeploy deployment. needs awscli, jq and corresponding iam permissions
#!/bin/bash
#your variables here, you can set AWS credentials here as well
AWS_REGION=$YourAWSRegion
DEP_GROUP=$NameOfYourCodeDeployDeploymentGroup
APP_NAME=$NameOfYourCDApplication
# list successfull deployments only
STATUS=Succeeded
# get the first (latest) deployment in list
DEPLOYMENT=$(aws deploy list-deployments --deployment-group-name $DEP_GROUP --region $AWS_REGION --application-name $APP_NAME --include-only-statuses $STATUS | jq '.deployments[0]' --raw-output)
# get detailed description of latest deployment
DEP_JSON=$(aws deploy get-deployment --deployment-id $DEPLOYMENT --region $AWS_REGION)
# filter the information you need
s3Bucket=$(echo "$DEP_JSON" | jq '.deploymentInfo.revision.s3Location.bucket' -r)
s3Key=$(echo "$DEP_JSON" | jq '.deploymentInfo.revision.s3Location.key' -r)
# just debug information
echo $DEPLOYMENT
echo $DEP_JSON
echo $s3Bucket/$s3Key
# get the infos and recreate the latest deployment
function create_deployment {
aws deploy create-deployment --application-name $APP_NAME --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name $DEP_GROUP --s3-location bucket=$s3Bucket,bundleType=zip,key=$s3Key --region $AWS_REGION
}
create_deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment