Skip to content

Commit eab0217

Browse files
authored
Merge pull request #5 from aws-samples/cdk_v2
Upgrade to CDK v2
2 parents 2403b5f + 844a338 commit eab0217

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Face
4242
## Prerequisites
4343
The following is required to run this example:
4444
- [git](https://git-scm.com/)
45-
- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)
45+
- [AWS CDK v2](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)
4646
- [Python](https://www.python.org/) 3.6+
4747
- [A virtual env](https://docs.python.org/3/library/venv.html#module-venv) (optional)
4848

@@ -111,7 +111,7 @@ cached model:
111111
```python
112112
fs = efs.FileSystem(self, 'FileSystem',
113113
vpc=vpc,
114-
removal_policy=cdk.RemovalPolicy.DESTROY)
114+
removal_policy=RemovalPolicy.DESTROY)
115115
access_point = fs.add_access_point('MLAccessPoint',
116116
create_acl=efs.Acl(
117117
owner_gid='1001', owner_uid='1001', permissions='750'),
@@ -134,7 +134,7 @@ function = lambda_.DockerImageFunction(
134134
code=lambda_.DockerImageCode.from_image_asset(docker_folder,
135135
cmd=[filename+".handler"]),
136136
memory_size=8096,
137-
timeout=cdk.Duration.seconds(600),
137+
timeout=Duration.seconds(600),
138138
vpc=vpc,
139139
filesystem=lambda_.FileSystem.from_efs_access_point(
140140
access_point, '/mnt/hf_models_cache'),

app.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
aws_lambda as lambda_,
1010
aws_apigateway as api_gw,
1111
aws_efs as efs,
12-
aws_ec2 as ec2,
13-
core as cdk
12+
aws_ec2 as ec2
1413
)
14+
from aws_cdk import App, Stack, Duration, RemovalPolicy
15+
from constructs import Construct
1516

16-
17-
class ServerlessHuggingFaceStack(cdk.Stack):
18-
def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
17+
class ServerlessHuggingFaceStack(Stack):
18+
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
1919
super().__init__(scope, id, **kwargs)
2020

2121
# EFS needs to be setup in a VPC
@@ -24,7 +24,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
2424
# creates a file system in EFS to store cache models
2525
fs = efs.FileSystem(self, 'FileSystem',
2626
vpc=vpc,
27-
removal_policy=cdk.RemovalPolicy.DESTROY)
27+
removal_policy=RemovalPolicy.DESTROY)
2828
access_point = fs.add_access_point('MLAccessPoint',
2929
create_acl=efs.Acl(
3030
owner_gid='1001', owner_uid='1001', permissions='750'),
@@ -46,7 +46,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
4646
filename+".handler"]
4747
),
4848
memory_size=8096,
49-
timeout=cdk.Duration.seconds(600),
49+
timeout=Duration.seconds(600),
5050
vpc=vpc,
5151
filesystem=lambda_.FileSystem.from_efs_access_point(
5252
access_point, '/mnt/hf_models_cache'),
@@ -62,7 +62,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
6262
})
6363
])
6464

65-
app = cdk.App()
65+
app = App()
6666

6767
ServerlessHuggingFaceStack(app, "ServerlessHuggingFaceStack")
6868

cdk.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
2-
"app": "python3 app.py",
2+
"app": "python3.9 app.py",
33
"context": {
4-
"@aws-cdk/core:enableStackNameDuplicates": "true",
54
"aws-cdk:enableDiffNoFail": "true",
65
"@aws-cdk/core:stackRelativeExports": "true"
76
}

requirements.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
aws-cdk.core
2-
aws-cdk.aws_ecr
3-
aws-cdk.aws_lambda
4-
aws-cdk.aws_apigateway
1+
aws-cdk-lib>=2.0.0
2+
constructs>=10.0.0

0 commit comments

Comments
 (0)