def set_deploy_status(verb, region, role_arn, application, reset=None): """ Set the status of this deploy to started by setting a timestamp in the application's deploying-status-APPLICATION_NAME SSM parameter """ aws_client = AWS_Client() ssm_client = aws_client.create_client('ssm', region, role_arn) ssm_parameter_name = "deploying-status-{}".format(application) try: deploying_state = ssm_client.get_parameter(Name=ssm_parameter_name)['Parameter']['Value'] except ssm_client.exceptions.ParameterNotFound: deploying_state = "false" if verb == "start" and deploying_state != "false" and reset != True: logging.error("Refusing to deploy, since it looks like we're already deploying at this timestamp: {}".format(deploying_state)) exit(1) elif verb == "stop": new_state = "false" elif verb == "start": new_state = strftime("%Y%m%d%H%M%S", gmtime()) ssm_client.put_parameter( Name=ssm_parameter_name, Description="Whether we're deploying right now", Value=new_state, Type="String", Overwrite=True ) logging.info("Deployment status for {} updated".format(application))
#!/usr/bin/env python from akinaka.client.aws_client import AWS_Client import boto3 import time import datetime import sys from akinaka.libs import helpers import logging helpers.set_logger() aws_client = AWS_Client() class CopyRDS(): def __init__(self, region, source_role_arn, target_role_arn, snapshot_style, source_instance_name, overwrite_target, target_security_group, target_db_subnet, target_instance_name): self.region = region self.source_role_arn = source_role_arn self.target_role_arn = target_role_arn self.snapshot_style = snapshot_style self.source_instance_name = source_instance_name self.overwrite_target = overwrite_target self.target_security_group = target_security_group self.target_db_subnet = target_db_subnet self.target_instance_name = target_instance_name def copy_instance(self): logging.info("Starting RDS copy...")