Skip to content

Instantly share code, notes, and snippets.

@kgorskowski
Last active October 31, 2018 22:45
Show Gist options
  • Save kgorskowski/36e2427a2b43fd3055e3f7f28f8b55f5 to your computer and use it in GitHub Desktop.
Save kgorskowski/36e2427a2b43fd3055e3f7f28f8b55f5 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