From 8e441d4f4a25d0b6464af24cc48a09df787c1c88 Mon Sep 17 00:00:00 2001 From: Leo Thomas Date: Fri, 8 Jan 2021 14:34:15 -0800 Subject: [PATCH] added cdk.context.json --- .circleci/config.yml | 2 +- cdk.context.json | 45 ++++++++++++++++++++++++++++++++++++++++++++ stack/app.py | 24 ++++++++++++++--------- stack/config.py | 3 ++- 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 cdk.context.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 3ae0457..deaa658 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,7 +39,7 @@ jobs: name: develop branch deployed to staging cdk stack command: | if [ "${CIRCLE_BRANCH}" == "develop" ]; then - STAGE='staging' cdk deploy covid-api-lambda-staging --region us-east-1 --require-approval never + STAGE='staging' VPC_ID='vpc-0fa3007e738c7bbdf' cdk deploy covid-api-lambda-staging --region us-east-1 --require-approval never fi deploy-production: diff --git a/cdk.context.json b/cdk.context.json new file mode 100644 index 0000000..6f6924f --- /dev/null +++ b/cdk.context.json @@ -0,0 +1,45 @@ +{ + "vpc-provider:account=853558080719:filter.vpc-id=vpc-0fa3007e738c7bbdf:region=us-east-1:returnAsymmetricSubnets=true": { + "vpcId": "vpc-0fa3007e738c7bbdf", + "vpcCidrBlock": "10.0.0.0/16", + "availabilityZones": [], + "subnetGroups": [ + { + "name": "Private", + "type": "Private", + "subnets": [ + { + "subnetId": "subnet-04bc4ca3d119f6f6b", + "cidr": "10.0.128.0/18", + "availabilityZone": "us-east-1a", + "routeTableId": "rtb-0a01309e2f528c2bd" + }, + { + "subnetId": "subnet-0bcd0f2d9b9ac1c56", + "cidr": "10.0.192.0/18", + "availabilityZone": "us-east-1b", + "routeTableId": "rtb-05251cbc837438e6c" + } + ] + }, + { + "name": "Public", + "type": "Public", + "subnets": [ + { + "subnetId": "subnet-009875640f64d198a", + "cidr": "10.0.0.0/18", + "availabilityZone": "us-east-1a", + "routeTableId": "rtb-0b1d4d54a9d962398" + }, + { + "subnetId": "subnet-0e033da6876bf7014", + "cidr": "10.0.64.0/18", + "availabilityZone": "us-east-1b", + "routeTableId": "rtb-074500f27775c6bda" + } + ] + } + ] + } +} diff --git a/stack/app.py b/stack/app.py index 38c04d4..f8bf825 100644 --- a/stack/app.py +++ b/stack/app.py @@ -48,16 +48,15 @@ def __init__( memory: int = 1024, timeout: int = 30, concurrent: int = 100, - env: dict = {}, code_dir: str = "./", **kwargs: Any, ) -> None: """Define stack.""" - super().__init__(scope, id, *kwargs) + super().__init__(scope, id, **kwargs) # add cache if config.VPC_ID: - vpc = ec2.Vpc.from_lookup(self, f"{id}-vpc", vpc_id=config.VPC_ID) + vpc = ec2.Vpc.from_lookup(self, f"{id}-vpc", vpc_id=config.VPC_ID,) else: vpc = ec2.Vpc(self, f"{id}-vpc") @@ -153,16 +152,16 @@ def __init__( memory: Union[int, float] = 512, mincount: int = 1, maxcount: int = 50, - env: dict = {}, + task_env: dict = {}, code_dir: str = "./", **kwargs: Any, ) -> None: """Define stack.""" - super().__init__(scope, id, *kwargs) + super().__init__(scope, id, **kwargs) # add cache if config.VPC_ID: - vpc = ec2.Vpc.from_lookup(self, f"{id}-vpc", vpc_id=config.VPC_ID) + vpc = ec2.Vpc.from_lookup(self, f"{id}-vpc", vpc_id=config.VPC_ID,) else: vpc = ec2.Vpc(self, f"{id}-vpc") @@ -177,7 +176,7 @@ def __init__( LOG_LEVEL="error", ) ) - task_env.update(env) + task_env.update(task_env) fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService( self, @@ -246,7 +245,11 @@ def __init__( memory=config.TASK_MEMORY, mincount=config.MIN_ECS_INSTANCES, maxcount=config.MAX_ECS_INSTANCES, - env=config.ENV, + task_env=config.TASK_ENV, + env=dict( + account=os.environ["CDK_DEFAULT_ACCOUNT"], + region=os.environ["CDK_DEFAULT_REGION"], + ), ) lambda_stackname = f"{config.PROJECT_NAME}-lambda-{config.STAGE}" @@ -256,7 +259,10 @@ def __init__( memory=config.MEMORY, timeout=config.TIMEOUT, concurrent=config.MAX_CONCURRENT, - env=config.ENV, + env=dict( + account=os.environ["CDK_DEFAULT_ACCOUNT"], + region=os.environ["CDK_DEFAULT_REGION"], + ), ) app.synth() diff --git a/stack/config.py b/stack/config.py index a73dad3..cf182c2 100644 --- a/stack/config.py +++ b/stack/config.py @@ -9,12 +9,13 @@ BUCKET = "covid-eo-data" # Additional environement variable to set in the task/lambda -ENV: dict = dict() +TASK_ENV: dict = dict() # Existing VPC to point ECS/LAMBDA stacks towards. Defaults to creating a new # VPC if no ID is supplied. VPC_ID = os.environ.get("VPC_ID") + ################################################################################ # # # ECS #