forked from IMAP-Science-Operations-Center/sds-data-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_template_dev.py
71 lines (56 loc) · 2.04 KB
/
app_template_dev.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""Template for CDK Application"""
# Standard
import os
# Installed
from aws_cdk import App, Environment
# Local
from sds_data_manager.utils.stackbuilder import build_sds
"""
This app is used for individual developer testing, instead of app.py.
When deploying locally, you can update the sds_id to include your
initials and distinguish your stack from the main dev stack or
other developers.
IMPORTANT: You will need to make a copy of app_template_dev.py file
with a different name (app_<name>_dev.py) and keep a copy of it
locally so that it will not be committed.
To deploy this app:
1. Install the required tools and activate the virtual environment:
- nvm use
- npm install -g aws-cdk
- source .env/bin/activate
2. Set the appropriate environment variables:
- export AWS_PROFILE=<profile>
3. Run the CDK commands:
- cdk synth --app "python app_template_dev.py"
- cdk diff --app "python app_template_dev.py"
- cdk deploy --app "python app_template_dev.py" [ stack | --all ]
- cdk destroy --app "python app_template_dev.py" [ stack | --all ]
"""
# Update with the AWS profile name you want to require for these builds
REQUIRED_PROFILE = "<profile>"
# Update with your initials or some other identifier
INITIALS = "<initials>"
current_profile = os.environ.get("AWS_PROFILE", "")
if current_profile != REQUIRED_PROFILE:
raise ValueError(
f"Wrong AWS Account set! Got: [{current_profile}], "
f"but expected: [{REQUIRED_PROFILE}]"
)
# These are set based on the current AWS profile
region = os.environ["CDK_DEFAULT_REGION"]
account = os.environ["CDK_DEFAULT_ACCOUNT"]
env = Environment(account=account, region=region)
app = App()
params = app.node.try_get_context("dev")
# sds_id = "abc-dev"
sds_id = f"{INITIALS}-{params['sds_id']}"
print(f"Using the profile [{current_profile}] in region [{region}].")
print(f"The stack identifier being used is: {sds_id}")
stacks = build_sds(
app,
env=env,
sds_id=sds_id,
use_custom_domain=True,
)
app.synth()