Skip to content

Commit

Permalink
chore: migrate to CDK v2
Browse files Browse the repository at this point in the history
- `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
  • Loading branch information
kikuomax committed Jan 31, 2022
1 parent cfe50fb commit 1a80d1c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -32,7 +37,7 @@ export type PythonLibraryLayerProps = {
*/
export class PythonLibraryLayer extends lambda.LayerVersion {
constructor(
scope: cdk.Construct,
scope: Construct,
id: string,
props: PythonLibraryLayerProps,
) {
Expand All @@ -41,23 +46,23 @@ 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
fsx.copySync(
path.join(__dirname, 'Dockerfile'),
path.join(stageDir, 'Dockerfile'),
);
const image = cdk.DockerImage.fromBuild(stageDir, {
const image = DockerImage.fromBuild(stageDir, {
buildArgs: {
IMAGE: runtime.bundlingImage.image,
},
});

// 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, {
Expand Down

0 comments on commit 1a80d1c

Please sign in to comment.