From 1a80d1cb8c040644e1f1602eb2184650568c8d52 Mon Sep 17 00:00:00 2001 From: Kikuo Emoto Date: Tue, 1 Feb 2022 00:40:30 +0900 Subject: [PATCH] chore: migrate to CDK v2 - `cdk.*` classes are imported from new modules, - `Construct` is from `constructs`. - `AssetStaging`, `FileSystem`, and `DockerImage` are from `aws-cdk-lib`. - `aws_lambda` is imported as `lambda` from `aws-cdk-lib`. issue #1 --- src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index d60ff6e..a34fd55 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,13 @@ import * as fsx from 'fs-extra'; import * as path from 'path'; -import * as cdk from '@aws-cdk/core'; -import * as lambda from '@aws-cdk/aws-lambda'; +import { + aws_lambda as lambda, + AssetStaging, + FileSystem, + DockerImage, +} from 'aws-cdk-lib'; +import { Construct } from 'constructs'; /** Properties for `PythonLibraryLayer`. */ export type PythonLibraryLayerProps = { @@ -32,7 +37,7 @@ export type PythonLibraryLayerProps = { */ export class PythonLibraryLayer extends lambda.LayerVersion { constructor( - scope: cdk.Construct, + scope: Construct, id: string, props: PythonLibraryLayerProps, ) { @@ -41,7 +46,7 @@ export class PythonLibraryLayer extends lambda.LayerVersion { // duplicates the library in a working directory // a Docker image is built inside this directory - const stageDir = cdk.FileSystem.mkdtemp('python-library-'); + const stageDir = FileSystem.mkdtemp('python-library-'); fsx.copySync(entry, stageDir); // builds a Docker image with the library installed in /var/packaged @@ -49,7 +54,7 @@ export class PythonLibraryLayer extends lambda.LayerVersion { path.join(__dirname, 'Dockerfile'), path.join(stageDir, 'Dockerfile'), ); - const image = cdk.DockerImage.fromBuild(stageDir, { + const image = DockerImage.fromBuild(stageDir, { buildArgs: { IMAGE: runtime.bundlingImage.image, }, @@ -57,7 +62,7 @@ export class PythonLibraryLayer extends lambda.LayerVersion { // script to run during bundling // outputs the installed library - const outputPath = `${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/python`; + const outputPath = `${AssetStaging.BUNDLING_OUTPUT_DIR}/python`; const script = `rsync -r /var/packaged/. ${outputPath}`; super(scope, id, {