Created
July 30, 2018 11:20
-
-
Save toshke/e530a588e68903b135ded78a35fb54c7 to your computer and use it in GitHub Desktop.
python code deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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