Skip to content

Commit

Permalink
👌 IMPROVE: Add aws_region as env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
caiovfernandes committed Jul 4, 2023
1 parent fe27360 commit 8d606dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/clone_blue_environment.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import json
import logging
import time
import os

# noqa: E502


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)
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/swap_environment.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import json
import time
import aws_authentication
import os


BLUE_CNAME_CONFIG_FILE = "blue_green_assets/blue_cname.json"


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)
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/terminate_green_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d606dd

Please sign in to comment.