Skip to content

Instantly share code, notes, and snippets.

@toshke
Created July 30, 2018 11:20
Show Gist options
  • Save toshke/e530a588e68903b135ded78a35fb54c7 to your computer and use it in GitHub Desktop.
Save toshke/e530a588e68903b135ded78a35fb54c7 to your computer and use it in GitHub Desktop.
python code deploy
#!/usr/bin/env python -u
import boto3
import os
import time
import sys
codedeploy = boto3.client('codedeploy',region_name=os.environ['AWS_REGION'])
application = os.environ['APPLICATION']
codedeploy_bucket = os.environ['CODEDEPLOY_BUCKET']
codedeploy_path = os.environ['CODEDEPLOY_PATH']
env = os.environ['ENVIRONMENT_NAME']
deployment = codedeploy.create_deployment(
applicationName="%s-%s" % (env, application),
deploymentGroupName="%s-backend" % (env),
revision={
'revisionType':'S3',
's3Location': {
'bucket': codedeploy_bucket,
'key': codedeploy_path,
'bundleType': 'zip'
}
}
)
deploymentId = deployment['deploymentId']
timeout=600
increment=10
start = time.time()
while True:
deployment = codedeploy.get_deployment(deploymentId=deploymentId)
status = deployment['deploymentInfo']['status']
if status == 'InProgress':
print "Deployment %s in progress" % deploymentId
if status == 'Succeeded':
print "Deployment %s complete" % deploymentId
sys.exit(0)
if status == 'Failed':
print "Deployment %s failed " % deploymentId
sys.exit(-1)
time.sleep(increment)
if (time.time() - start) > timeout:
print "Maximum timeout of %s seconds elapsed, exiting.." % timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment