-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.py
49 lines (39 loc) · 1.88 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
"""Serves as the dev and production deployment app.
The app defaults to a dev deployment via a default `account_name` value in
`cdk.json.`
To deploy to prod, specify `--context account_name=prod`.
To deploy to the backup account (only deploys required backup stacks),
specify `--context account_name=backup`.
"""
from aws_cdk import App, Environment
from sds_data_manager.utils.stackbuilder import build_backup, build_sds
app = App()
# Grab values from context
# account_name is the section we are looking for parameters in
# within the cdk.json file:
# "account_name": {"account": "0123", "region": "us-west-2", ...}
# This can be overridden via the command line: `--context account_name=prod`
account_name = app.node.get_context("account_name")
# once we have the account_name, get that section out of cdk.json
account_config = app.node.get_context(account_name)
# Add the account_name to the account_config for later lookup
# and using it within the stacks without needing to pass an extra variable
account_config["account_name"] = account_name
account = account_config["account"]
region = account_config["region"]
env = Environment(account=account, region=region)
print(f"Using the {account_name} account [{account}] in the {region} region.")
if account_name == "backup":
# Deploy backup resources
# The source account is the account that owns the source bucket.
# Lookup the name of that account, then go and get that account
# number from its own context section
source_account_name = account_config["source_account"]
source_account_config = app.node.get_context(source_account_name)
source_account = source_account_config["account"]
build_backup(app, env=env, source_account=source_account)
else:
# Deploy SDS resources. This is the default with no CLI context variables set.
build_sds(app, env=env, account_config=account_config)
app.synth()