diff --git a/README.md b/README.md index 8b5432c..ce97bdc 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Face ## Prerequisites The following is required to run this example: - [git](https://git-scm.com/) -- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) +- [AWS CDK v2](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html) - [Python](https://www.python.org/) 3.6+ - [A virtual env](https://docs.python.org/3/library/venv.html#module-venv) (optional) @@ -111,7 +111,7 @@ cached model: ```python fs = efs.FileSystem(self, 'FileSystem', vpc=vpc, -removal_policy=cdk.RemovalPolicy.DESTROY) +removal_policy=RemovalPolicy.DESTROY) access_point = fs.add_access_point('MLAccessPoint', create_acl=efs.Acl( owner_gid='1001', owner_uid='1001', permissions='750'), @@ -134,7 +134,7 @@ function = lambda_.DockerImageFunction( code=lambda_.DockerImageCode.from_image_asset(docker_folder, cmd=[filename+".handler"]), memory_size=8096, - timeout=cdk.Duration.seconds(600), + timeout=Duration.seconds(600), vpc=vpc, filesystem=lambda_.FileSystem.from_efs_access_point( access_point, '/mnt/hf_models_cache'), diff --git a/app.py b/app.py index aa0a3fd..2d75cae 100644 --- a/app.py +++ b/app.py @@ -9,13 +9,13 @@ aws_lambda as lambda_, aws_apigateway as api_gw, aws_efs as efs, - aws_ec2 as ec2, - core as cdk + aws_ec2 as ec2 ) +from aws_cdk import App, Stack, Duration, RemovalPolicy +from constructs import Construct - -class ServerlessHuggingFaceStack(cdk.Stack): - def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None: +class ServerlessHuggingFaceStack(Stack): + def __init__(self, scope: Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) # EFS needs to be setup in a VPC @@ -24,7 +24,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None: # creates a file system in EFS to store cache models fs = efs.FileSystem(self, 'FileSystem', vpc=vpc, - removal_policy=cdk.RemovalPolicy.DESTROY) + removal_policy=RemovalPolicy.DESTROY) access_point = fs.add_access_point('MLAccessPoint', create_acl=efs.Acl( owner_gid='1001', owner_uid='1001', permissions='750'), @@ -46,7 +46,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None: filename+".handler"] ), memory_size=8096, - timeout=cdk.Duration.seconds(600), + timeout=Duration.seconds(600), vpc=vpc, filesystem=lambda_.FileSystem.from_efs_access_point( access_point, '/mnt/hf_models_cache'), @@ -62,7 +62,7 @@ def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None: }) ]) -app = cdk.App() +app = App() ServerlessHuggingFaceStack(app, "ServerlessHuggingFaceStack") diff --git a/cdk.json b/cdk.json index 0786210..051df2d 100644 --- a/cdk.json +++ b/cdk.json @@ -1,7 +1,6 @@ { - "app": "python3 app.py", + "app": "python3.9 app.py", "context": { - "@aws-cdk/core:enableStackNameDuplicates": "true", "aws-cdk:enableDiffNoFail": "true", "@aws-cdk/core:stackRelativeExports": "true" } diff --git a/requirements.txt b/requirements.txt index 9a1d0ff..de9d6d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ -aws-cdk.core -aws-cdk.aws_ecr -aws-cdk.aws_lambda -aws-cdk.aws_apigateway +aws-cdk-lib>=2.0.0 +constructs>=10.0.0 \ No newline at end of file