Skip to content

Commit

Permalink
added cdk.context.json
Browse files Browse the repository at this point in the history
  • Loading branch information
leothomas committed Jan 8, 2021
1 parent 98d3809 commit 8e441d4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 45 additions & 0 deletions cdk.context.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
}
24 changes: 15 additions & 9 deletions stack/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand All @@ -177,7 +176,7 @@ def __init__(
LOG_LEVEL="error",
)
)
task_env.update(env)
task_env.update(task_env)

fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(
self,
Expand Down Expand Up @@ -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}"
Expand All @@ -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()
3 changes: 2 additions & 1 deletion stack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down

0 comments on commit 8e441d4

Please sign in to comment.