-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (63 loc) · 2.76 KB
/
app.py
File metadata and controls
76 lines (63 loc) · 2.76 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
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import aws_cdk as cdk
import boto3
import cdk_nag
from aws_cdk import Aspects
from cdk_packages.perfbench import PerfBench
from cdk_packages.downloader import Downloader
class Params:
"""
A class to hold all parameters exchanged across stacks in one place.
"""
"""
Set the environment explicitly. This is necessary to get subnets in all availability zones.
See also: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Stack.html#availabilityzones
"If the stack is environment-agnostic (either account and/or region are tokens), this property
will return an array with 2 tokens that will resolve at deploy-time to the first two availability
zones returned from CloudFormation's Fn::GetAZs intrinsic function."
"""
environment = cdk.Environment(
account=boto3.client('sts').get_caller_identity().get('Account'),
region=boto3.session.Session().region_name)
environment_eu_west_1 = cdk.Environment(
account=boto3.client('sts').get_caller_identity().get('Account'),
region='eu_west_1')
# ensure we are in the right region
if environment.region != 'us-west-2':
raise ValueError(
f'This CDK application needs to be deployed in the AWS region us-west-2. '
f'You are attempting a deployment into region {environment.region}.'
)
# ensure the ECR repository for the NVIDIA CUDA container exist
ecr_client = boto3.client('ecr')
ecr_repositories = ecr_client.describe_repositories()['repositories']
ecr_repository_names = [repository['repositoryName'] for repository in ecr_repositories]
if 'nvidia/cuda' not in ecr_repository_names:
raise ValueError(
'The ECR repository "nvidia/cuda" does not exist. '
'This repository needs to be created manually. Please ensure you follow the instructions in the README.md.'
)
# ensure the NVIDIA CUDA image exists in ECR repository
ecr_images = ecr_client.describe_images(repositoryName='nvidia/cuda')
if len(ecr_images['imageDetails']) < 1:
raise ValueError(
'The ECR repository "nvidia/cuda" does not contain any container images. '
'The NVIDIA CUDA image needs to be pushed manually. Please ensure you follow the instructions in the README.md.'
)
params = Params()
app = cdk.App()
# cdk-nag: Check for compliance with CDK best practices
# https://github.com/cdklabs/cdk-nag
# Uncomment the following line to run the cdk-nag checks
Aspects.of(app).add(cdk_nag.AwsSolutionsChecks(verbose=True))
params.perfbench = PerfBench(
app, 'ONT-PerfBench',
description='ONT performance benchmark environment',
env=environment
)
params.downloader = Downloader(
app, 'ONT-PerfBench-Downloader', params=params.perfbench.params,
description='EC2 instance for automated download of performance test data set.',
env=environment
)
app = app.synth()