-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (57 loc) · 2.27 KB
/
Copy pathapp.py
File metadata and controls
66 lines (57 loc) · 2.27 KB
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
"""
Copyright © Amazon.com and Affiliates
"""
import os
from pathlib import Path
import logging
import sys
import aws_cdk as cdk
import yaml
from cdk_nag import AwsSolutionsChecks, NagSuppressions
from yaml.loader import SafeLoader
from infra.stack import IDPBedrockStack
LOGGER = logging.Logger("APP-BUILD", level=logging.DEBUG)
HANDLER = logging.StreamHandler(sys.stdout)
HANDLER.setFormatter(
logging.Formatter("%(asctime)s | %(levelname)s | %(name)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
)
LOGGER.addHandler(HANDLER)
ROOT = Path(__file__).parent
if "config.yml" in os.listdir(ROOT):
LOGGER.info("Found config.yml file in root directory.")
STACK_CONFIG_PATH = os.path.join(ROOT, "config.yml")
elif "config-example.yml" in os.listdir(ROOT):
LOGGER.warning("Did not find config.yml but using config-example.yml from the root directory.")
STACK_CONFIG_PATH = os.path.join(ROOT, "config-example.yml")
else:
raise RuntimeError("Cannot find config file in root directory.")
with open(STACK_CONFIG_PATH, "r", encoding="utf-8") as yaml_file:
stack_config = yaml.load(yaml_file, Loader=SafeLoader)
LOGGER.info("Creating app scope")
app = cdk.App()
env = cdk.Environment(account=os.getenv("CDK_DEFAULT_ACCOUNT"), region=stack_config["stack_region"])
LOGGER.info(f"Creating solution stack using {env=} and {stack_config=}")
stack = IDPBedrockStack(scope=app, stack_name=stack_config["stack_name"], config=stack_config, env=env)
NagSuppressions.add_stack_suppressions(
stack,
[
{"id": "AwsSolutions-IAM4", "reason": "Using default AWS managed policy for CloudWatch logs for API Gateway"},
{"id": "AwsSolutions-CFR4", "reason": "Using default CloudFront settings"},
{"id": "AwsSolutions-CFR5", "reason": "Using default CloudFront settings"},
{
"id": "AwsSolutions-EC23",
"reason": "False positive, all traffic is only allowed within the same security group",
},
{
"id": "AwsSolutions-IAM5",
"reason": "CognitoUpdaterRole needs wildcard log access for its Lambda function.",
},
],
True,
)
if stack_config["cdk_nag"]:
LOGGER.info("Running cdk-nag")
cdk.Aspects.of(app).add(AwsSolutionsChecks())
LOGGER.info("Synthesizing app")
app.synth()
LOGGER.info("Done!")