diff --git a/src/clone_blue_environment.py b/src/clone_blue_environment.py index 4be65f3..68f3766 100644 --- a/src/clone_blue_environment.py +++ b/src/clone_blue_environment.py @@ -1,6 +1,7 @@ import json import logging import time +import os # noqa: E502 @@ -8,9 +9,9 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, BEANSTALK_APP_NAME, S3_ARTIFACTS_BUCKET, boto_authenticated_client): beanstalkclient = boto_authenticated_client.client( - 'elasticbeanstalk', region_name='us-east-1') + 'elasticbeanstalk', region_name=os.environ['AWS_DEFAULT_REGION']) s3client = boto_authenticated_client.client( - 's3', region_name='us-east-1') + 's3', region_name=os.environ['AWS_DEFAULT_REGION']) blue_env_info = get_env_info(beanstalkclient, BLUE_ENV_NAME) @@ -105,14 +106,14 @@ def wait_green_be_ready(beanstalkclient, GREEN_ENV_NAME): green_env_info = get_env_info(beanstalkclient, GREEN_ENV_NAME) while green_env_info["Environments"][0]["Status"] != "Ready": print("Waiting the blue environment be Ready!") - time.sleep(60) + time.sleep(10) green_env_info = get_env_info(beanstalkclient, GREEN_ENV_NAME) def rollback_created_env(boto_authenticated_client, environment_name): ''' Terminate a beanstalk environment''' beanstalkclient = boto_authenticated_client.client( - 'elasticbeanstalk', region_name='us-east-1') + 'elasticbeanstalk', region_name=os.environ['AWS_DEFAULT_REGION']) green_env_info = get_env_info(beanstalkclient, environment_name) if len(green_env_info["Environments"]) == 0: diff --git a/src/swap_environment.py b/src/swap_environment.py index 7453bc1..4d47359 100644 --- a/src/swap_environment.py +++ b/src/swap_environment.py @@ -1,6 +1,6 @@ import json import time -import aws_authentication +import os BLUE_CNAME_CONFIG_FILE = "blue_green_assets/blue_cname.json" @@ -8,13 +8,13 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, S3_ARTIFACTS_BUCKET, BEANSTALK_APP_NAME, boto_authenticated_client): beanstalkclient = boto_authenticated_client.client( - "elasticbeanstalk", region_name="us-east-1") + "elasticbeanstalk", region_name=os.environ['AWS_DEFAULT_REGION']) s3client = boto_authenticated_client.client( - 's3', region_name='us-east-1') + 's3', region_name=os.environ['AWS_DEFAULT_REGION']) route53_client = boto_authenticated_client.client( - 'route53', region_name='us-east-1') + 'route53', region_name=os.environ['AWS_DEFAULT_REGION']) ssm_client = boto_authenticated_client.client( - 'ssm', region_name='us-east-1') + 'ssm', region_name=os.environ['AWS_DEFAULT_REGION']) blue_env_url = get_env_address( BLUE_CNAME_CONFIG_FILE, S3_ARTIFACTS_BUCKET, s3client) @@ -107,7 +107,7 @@ def create_route53_records(route53_client, applications_list, green_env_url, hos "ResourceRecordSet": { "Type": "CNAME", "Name": record, - "Region": "us-east-1", + "Region": os.environ['AWS_DEFAULT_REGION'], "SetIdentifier": f"{record} Identifier", "TTL": 60, "ResourceRecords": [ @@ -135,9 +135,9 @@ def re_swap_dns(boto_authenticated_client, S3_ARTIFACTS_BUCKET, GREEN_ENV_NAME, '''Re-swap beanstalk environments Domains applying the rollback''' beanstalkclient = boto_authenticated_client.client( - "elasticbeanstalk", region_name="us-east-1") + "elasticbeanstalk", region_name=os.environ['AWS_DEFAULT_REGION']) s3client = boto_authenticated_client.client( - 's3', region_name='us-east-1') + 's3', region_name=os.environ['AWS_DEFAULT_REGION']) blue_env_url = get_env_address( BLUE_CNAME_CONFIG_FILE, S3_ARTIFACTS_BUCKET, s3client diff --git a/src/terminate_green_env.py b/src/terminate_green_env.py index 45e91b6..f83c7c5 100644 --- a/src/terminate_green_env.py +++ b/src/terminate_green_env.py @@ -5,8 +5,8 @@ def main(BLUE_ENV_NAME, GREEN_ENV_NAME, BEANSTALK_APP_NAME, boto_authenticated_client): CREATE_CONFIG_TEMPLATE_NAME = "BlueEnvConfig" - beanstalkclient = boto_authenticated_client.client('elasticbeanstalk',region_name='us-east-1') - s3client = boto_authenticated_client.client('s3',region_name='us-east-1') + beanstalkclient = boto_authenticated_client.client('elasticbeanstalk',region_name=os.environ['AWS_DEFAULT_REGION']) + s3client = boto_authenticated_client.client('s3',region_name=os.environ['AWS_DEFAULT_REGION']) try: print("Starting the job") # Extract the Job Data