From 6bc24d1ef82654cf0088634d485b9d49f75bcb0b Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 18 Dec 2021 02:27:12 -0800 Subject: [PATCH 01/42] feat: refactor bundling to use `cdk.BundlingOptions` --- .../aws-lambda-python/lib/bundling.ts | 102 ++++++++++-------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 722cd2d062fb6..3e42af6450824 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as lambda from '@aws-cdk/aws-lambda'; +import { Architecture, AssetCode, Code, Runtime } from '@aws-cdk/aws-lambda'; import * as cdk from '@aws-cdk/core'; /** @@ -16,7 +16,7 @@ export const BUNDLER_DEPENDENCIES_CACHE = '/var/dependencies'; /** * Options for bundling */ -export interface BundlingOptions { +export interface BundlingProps { /** * Entry path */ @@ -25,18 +25,25 @@ export interface BundlingOptions { /** * The runtime of the lambda function */ - readonly runtime: lambda.Runtime; + readonly runtime: Runtime; /** * The system architecture of the lambda function */ - readonly architecture: lambda.Architecture; + readonly architecture: Architecture; /** * Output path suffix ('python' for a layer, '.' otherwise) */ readonly outputPathSuffix: string; + /** + * Docker image to use for bundling. If no options are provided, the default bundling image + * will be used. The bundling Docker image must have `rsync` installed. Dependencies will be + * copied from the image's`/var/dependencies` directory into the Lambda asset. + */ + readonly image?: cdk.DockerImage; + /** * Determines how asset hash is calculated. Assets will get rebuild and * uploaded only if their hash has changed. @@ -81,45 +88,54 @@ export interface BundlingOptions { /** * Produce bundled Lambda asset code */ -export function bundle(options: BundlingOptions): lambda.Code { - const { entry, runtime, architecture, outputPathSuffix } = options; - - const stagedir = cdk.FileSystem.mkdtemp('python-bundling-'); - const hasDeps = stageDependencies(entry, stagedir); - - const depsCommand = chain([ - hasDeps ? `rsync -r ${BUNDLER_DEPENDENCIES_CACHE}/. ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}` : '', - `rsync -r . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}`, - ]); - - // Determine which dockerfile to use. When dependencies are present, we use a - // Dockerfile that can create a cacheable layer. We can't use this Dockerfile - // if there aren't dependencies or the Dockerfile will complain about missing - // sources. - const dockerfile = hasDeps - ? 'Dockerfile.dependencies' - : 'Dockerfile'; - - // copy Dockerfile to workdir - fs.copyFileSync(path.join(__dirname, dockerfile), path.join(stagedir, dockerfile)); - - const image = cdk.DockerImage.fromBuild(stagedir, { - buildArgs: { - IMAGE: runtime.bundlingImage.image, - }, - platform: architecture.dockerPlatform, - file: dockerfile, - }); - - return lambda.Code.fromAsset(entry, { - assetHashType: options.assetHashType, - assetHash: options.assetHash, - exclude: DEPENDENCY_EXCLUDES, - bundling: { - image, - command: ['bash', '-c', depsCommand], - }, - }); +export class Bundling implements cdk.BundlingOptions { + public static bundle(options: BundlingProps): AssetCode { + return Code.fromAsset(options.entry, { + assetHash: options.assetHash, + assetHashType: options.assetHashType, + exclude: DEPENDENCY_EXCLUDES, + bundling: new Bundling(options), + }); + + } + + public readonly image: cdk.DockerImage; + public readonly command: string[]; + + + constructor(props: BundlingProps) { + + const { entry, runtime, architecture, outputPathSuffix } = props; + + const stagedir = cdk.FileSystem.mkdtemp('python-bundling-'); + const hasDeps = stageDependencies(entry, stagedir); + + const depsCommand = chain([ + hasDeps ? `rsync -r ${BUNDLER_DEPENDENCIES_CACHE}/. ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}` : '', + `rsync -r . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}`, + ]); + + // Determine which dockerfile to use. When dependencies are present, we use a + // Dockerfile that can create a cacheable layer. We can't use this Dockerfile + // if there aren't dependencies or the Dockerfile will complain about missing + // sources. + const dockerfile = hasDeps + ? 'Dockerfile.dependencies' + : 'Dockerfile'; + + // copy Dockerfile to workdir + fs.copyFileSync(path.join(__dirname, dockerfile), path.join(stagedir, dockerfile)); + + const defaultImage = cdk.DockerImage.fromBuild(stagedir, { + buildArgs: { + IMAGE: runtime.bundlingImage.image, + }, + platform: architecture.dockerPlatform, + file: dockerfile, + }); + this.image = props.image ?? defaultImage; + this.command = ['bash', '-c', depsCommand]; + } } /** From 1d018bbbbb5f63aa4bc4c7ae1d913d760e73be50 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 18 Dec 2021 02:33:37 -0800 Subject: [PATCH 02/42] fix: Use updated `Bundling` class --- packages/@aws-cdk/aws-lambda-python/lib/function.ts | 4 ++-- packages/@aws-cdk/aws-lambda-python/lib/layer.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/function.ts b/packages/@aws-cdk/aws-lambda-python/lib/function.ts index 1aafeb61149f3..640457f492d87 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/function.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as lambda from '@aws-cdk/aws-lambda'; import { AssetHashType } from '@aws-cdk/core'; -import { bundle } from './bundling'; +import { Bundling } from './bundling'; // keep this import separate from other imports to reduce chance for merge conflicts with v2-main // eslint-disable-next-line no-duplicate-imports, import/order @@ -105,7 +105,7 @@ export class PythonFunction extends lambda.Function { super(scope, id, { ...props, runtime, - code: bundle({ + code: Bundling.bundle({ runtime, architecture, entry, diff --git a/packages/@aws-cdk/aws-lambda-python/lib/layer.ts b/packages/@aws-cdk/aws-lambda-python/lib/layer.ts index 4f247acc10bae..529e93ba4151d 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/layer.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/layer.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import * as lambda from '@aws-cdk/aws-lambda'; -import { bundle } from './bundling'; +import { Bundling } from './bundling'; // keep this import separate from other imports to reduce chance for merge conflicts with v2-main // eslint-disable-next-line no-duplicate-imports, import/order @@ -54,7 +54,7 @@ export class PythonLayerVersion extends lambda.LayerVersion { super(scope, id, { ...props, compatibleRuntimes, - code: bundle({ + code: Bundling.bundle({ entry, runtime, architecture, From 41230349498ff6c7fc632c2cb454e29df8f5689d Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 18 Dec 2021 02:34:32 -0800 Subject: [PATCH 03/42] test: Update tests to use updated `Bundling` class --- .../aws-lambda-python/test/bundling.test.ts | 12 ++-- .../aws-lambda-python/test/function.test.ts | 60 ++++++++++--------- .../aws-lambda-python/test/layer.test.ts | 28 +++++---- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index 5043a1501853e..cbc384aec599c 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { Architecture, Code, Runtime } from '@aws-cdk/aws-lambda'; import { DockerImage, FileSystem } from '@aws-cdk/core'; -import { stageDependencies, bundle } from '../lib/bundling'; +import { stageDependencies, Bundling } from '../lib/bundling'; jest.spyOn(Code, 'fromAsset'); jest.spyOn(DockerImage, 'fromBuild'); @@ -26,7 +26,7 @@ beforeEach(() => { test('Bundling a function without dependencies', () => { const entry = path.join(__dirname, 'lambda-handler-nodeps'); - bundle({ + Bundling.bundle({ entry: entry, runtime: Runtime.PYTHON_3_7, architecture: Architecture.X86_64, @@ -53,7 +53,7 @@ test('Bundling a function without dependencies', () => { test('Bundling a function with requirements.txt installed', () => { const entry = path.join(__dirname, 'lambda-handler'); - bundle({ + Bundling.bundle({ entry: entry, runtime: Runtime.PYTHON_3_7, architecture: Architecture.X86_64, @@ -73,7 +73,7 @@ test('Bundling a function with requirements.txt installed', () => { test('Bundling Python 2.7 with requirements.txt installed', () => { const entry = path.join(__dirname, 'lambda-handler'); - bundle({ + Bundling.bundle({ entry: entry, runtime: Runtime.PYTHON_2_7, architecture: Architecture.X86_64, @@ -94,7 +94,7 @@ test('Bundling Python 2.7 with requirements.txt installed', () => { test('Bundling a layer with dependencies', () => { const entry = path.join(__dirname, 'lambda-handler'); - bundle({ + Bundling.bundle({ entry: entry, runtime: Runtime.PYTHON_3_9, architecture: Architecture.X86_64, @@ -114,7 +114,7 @@ test('Bundling a layer with dependencies', () => { test('Bundling a python code layer', () => { const entry = path.join(__dirname, 'lambda-handler-nodeps'); - bundle({ + Bundling.bundle({ entry: path.join(entry, '.'), runtime: Runtime.PYTHON_3_9, architecture: Architecture.X86_64, diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 31450f0a7c43c..940404b0b5cd6 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -2,37 +2,39 @@ import { Template } from '@aws-cdk/assertions'; import { Code, Runtime } from '@aws-cdk/aws-lambda'; import { AssetHashType, AssetOptions, Stack } from '@aws-cdk/core'; import { PythonFunction } from '../lib'; -import { bundle } from '../lib/bundling'; +import { Bundling } from '../lib/bundling'; jest.mock('../lib/bundling', () => { return { - bundle: jest.fn().mockImplementation((options: AssetOptions): Code => { - const mockObjectKey = (() => { - const hashType = options.assetHashType ?? (options.assetHash ? 'custom' : 'source'); - switch (hashType) { - case 'source': return 'SOURCE_MOCK'; - case 'output': return 'OUTPUT_MOCK'; - case 'custom': { - if (!options.assetHash) { throw new Error('no custom hash'); } - return options.assetHash; + Bundling: { + bundle: jest.fn().mockImplementation((options: AssetOptions): Code => { + const mockObjectKey = (() => { + const hashType = options.assetHashType ?? (options.assetHash ? 'custom' : 'source'); + switch (hashType) { + case 'source': return 'SOURCE_MOCK'; + case 'output': return 'OUTPUT_MOCK'; + case 'custom': { + if (!options.assetHash) { throw new Error('no custom hash'); } + return options.assetHash; + } } - } - - throw new Error('unexpected asset hash type'); - })(); - - return { - isInline: false, - bind: () => ({ - s3Location: { - bucketName: 'mock-bucket-name', - objectKey: mockObjectKey, - }, - }), - bindToResource: () => { return; }, - }; - }), - hasDependencies: jest.fn().mockReturnValue(false), + + throw new Error('unexpected asset hash type'); + })(); + + return { + isInline: false, + bind: () => ({ + s3Location: { + bucketName: 'mock-bucket-name', + objectKey: mockObjectKey, + }, + }), + bindToResource: () => { return; }, + }; + }), + hasDependencies: jest.fn().mockReturnValue(false), + }, }; }); @@ -48,7 +50,7 @@ test('PythonFunction with defaults', () => { runtime: Runtime.PYTHON_3_8, }); - expect(bundle).toHaveBeenCalledWith(expect.objectContaining({ + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ entry: expect.stringMatching(/aws-lambda-python\/test\/lambda-handler$/), outputPathSuffix: '.', })); @@ -66,7 +68,7 @@ test('PythonFunction with index in a subdirectory', () => { runtime: Runtime.PYTHON_3_8, }); - expect(bundle).toHaveBeenCalledWith(expect.objectContaining({ + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ entry: expect.stringMatching(/aws-lambda-python\/test\/lambda-handler-sub$/), outputPathSuffix: '.', })); diff --git a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts index 4f0199878a205..501f2a27c696b 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts @@ -1,22 +1,24 @@ import * as path from 'path'; import { Runtime } from '@aws-cdk/aws-lambda'; import { Stack } from '@aws-cdk/core'; -import { stageDependencies, bundle } from '../lib/bundling'; +import { stageDependencies, Bundling } from '../lib/bundling'; import { PythonLayerVersion } from '../lib/layer'; jest.mock('../lib/bundling', () => { return { - bundle: jest.fn().mockReturnValue({ - bind: () => { - return { - s3Location: { - bucketName: 'bucket', - objectKey: 'key', - }, - }; - }, - bindToResource: () => { return; }, - }), + Bundling: { + bundle: jest.fn().mockReturnValue({ + bind: () => { + return { + s3Location: { + bucketName: 'bucket', + objectKey: 'key', + }, + }; + }, + bindToResource: () => { return; }, + }), + }, stageDependencies: jest.fn().mockReturnValue(true), }; }); @@ -37,7 +39,7 @@ test('Bundling a layer from files', () => { entry, }); - expect(bundle).toHaveBeenCalledWith(expect.objectContaining({ + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ entry, outputPathSuffix: 'python', })); From 69ebdaac7091a30f5c40f4d1e111234e2fe8495d Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 22:47:19 -0800 Subject: [PATCH 04/42] feat: Add new `Packaging` class --- .../aws-lambda-python/lib/packaging.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda-python/lib/packaging.ts diff --git a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts new file mode 100644 index 0000000000000..71e490974b66c --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts @@ -0,0 +1,50 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +export enum DependenciesFile { + PIP = 'requirements.txt', + POETRY = 'poetry.lock', + PIPENV = 'Pipfile.lock', + NONE = '' +} + +interface PackagingProps { + dependenciesFile: DependenciesFile; + exportCommand?: string; +} + +export class Packaging { + public static PIP = new Packaging({ + dependenciesFile: DependenciesFile.PIP, + }); + public static PIPENV = new Packaging({ + dependenciesFile: DependenciesFile.PIPENV, + // By default, pipenv creates a virtualenv in `/.local`, so we force it to create one in the package directory. + // At the end, we remove the virtualenv to avoid creating a duplicate copy in the Lambda package. + exportCommand: `PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > ${DependenciesFile.PIP} && rm -rf .venv`, + }); + public static POETRY = new Packaging({ + dependenciesFile: DependenciesFile.POETRY, + exportCommand: `poetry export --with-credentials --format ${DependenciesFile.PIP} --output ${DependenciesFile.PIP}`, + }); + public static NONE = new Packaging({ dependenciesFile: DependenciesFile.NONE }); + + public static fromEntry(entry: string): Packaging { + if (fs.existsSync(path.join(entry, DependenciesFile.PIPENV))) { + return Packaging.PIPENV; + } if (fs.existsSync(path.join(entry, DependenciesFile.POETRY))) { + return Packaging.POETRY; + } else if (fs.existsSync(path.join(entry, DependenciesFile.PIP))) { + return Packaging.PIP; + } else { + return Packaging.NONE; + } + } + + public readonly dependenciesFile: string; + public readonly exportCommand?: string; + constructor(props: PackagingProps) { + this.dependenciesFile = props.dependenciesFile; + this.exportCommand = props.exportCommand; + } +} \ No newline at end of file From 97f1509b1d03ca62bc0a0c6a04069ec9d7eec5e2 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 22:51:59 -0800 Subject: [PATCH 05/42] refactor: Bundling to use `Packaging`, align with other Lambda functions --- .../@aws-cdk/aws-lambda-python/lib/Dockerfile | 5 +- .../lib/Dockerfile.dependencies | 22 ----- .../aws-lambda-python/lib/bundling.ts | 86 ++++++++----------- 3 files changed, 37 insertions(+), 76 deletions(-) delete mode 100644 packages/@aws-cdk/aws-lambda-python/lib/Dockerfile.dependencies diff --git a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile index ab45f0480735f..26928bbbb1df4 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile +++ b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile @@ -3,7 +3,8 @@ ARG IMAGE=public.ecr.aws/sam/build-python3.7 FROM $IMAGE -# Ensure rsync is installed -RUN yum -q list installed rsync &>/dev/null || yum install -y rsync +# Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry) +RUN pip install --upgrade pip +RUN pip install pipenv poetry CMD [ "python" ] diff --git a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile.dependencies b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile.dependencies deleted file mode 100644 index 6793987212603..0000000000000 --- a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile.dependencies +++ /dev/null @@ -1,22 +0,0 @@ -# The correct AWS SAM build image based on the runtime of the function will be -# passed as build arg. The default allows to do `docker build .` when testing. -ARG IMAGE=public.ecr.aws/sam/build-python3.7 -FROM $IMAGE - -# Ensure rsync is installed -RUN yum -q list installed rsync &>/dev/null || yum install -y rsync - -# Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry) -RUN pip install --upgrade pip - -# Install pipenv and poetry so we can create a requirements.txt if we detect pipfile or poetry.lock respectively -RUN pip install pipenv poetry - -# Install the dependencies in a cacheable layer -WORKDIR /var/dependencies -COPY Pipfile* pyproject* poetry* requirements.tx[t] ./ -RUN [ -f 'Pipfile' ] && pipenv lock -r >requirements.txt; \ - [ -f 'poetry.lock' ] && poetry export --with-credentials --format requirements.txt --output requirements.txt; \ - [ -f 'requirements.txt' ] && pip install -r requirements.txt -t .; - -CMD [ "python" ] diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 3e42af6450824..913f5218fdcba 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -1,7 +1,7 @@ -import * as fs from 'fs'; import * as path from 'path'; import { Architecture, AssetCode, Code, Runtime } from '@aws-cdk/aws-lambda'; -import * as cdk from '@aws-cdk/core'; +import { AssetHashType, AssetStaging, BundlingOptions, DockerImage } from '@aws-cdk/core'; +import { Packaging, DependenciesFile } from './packaging'; /** * Dependency files to exclude from the asset hash. @@ -35,14 +35,15 @@ export interface BundlingProps { /** * Output path suffix ('python' for a layer, '.' otherwise) */ - readonly outputPathSuffix: string; + readonly outputPathSuffix?: string; /** * Docker image to use for bundling. If no options are provided, the default bundling image * will be used. The bundling Docker image must have `rsync` installed. Dependencies will be * copied from the image's`/var/dependencies` directory into the Lambda asset. + * @default: - the default bundling image */ - readonly image?: cdk.DockerImage; + readonly image?: DockerImage; /** * Determines how asset hash is calculated. Assets will get rebuild and @@ -66,7 +67,7 @@ export interface BundlingProps { * default is `CUSTOM`. This means that only updates to the source will cause * the asset to rebuild. */ - readonly assetHashType?: cdk.AssetHashType; + readonly assetHashType?: AssetHashType; /** * Specify a custom hash for this asset. If `assetHashType` is set it must @@ -88,7 +89,7 @@ export interface BundlingProps { /** * Produce bundled Lambda asset code */ -export class Bundling implements cdk.BundlingOptions { +export class Bundling implements BundlingOptions { public static bundle(options: BundlingProps): AssetCode { return Code.fromAsset(options.entry, { assetHash: options.assetHash, @@ -96,73 +97,54 @@ export class Bundling implements cdk.BundlingOptions { exclude: DEPENDENCY_EXCLUDES, bundling: new Bundling(options), }); - } - public readonly image: cdk.DockerImage; + public readonly image: DockerImage; public readonly command: string[]; - constructor(props: BundlingProps) { const { entry, runtime, architecture, outputPathSuffix } = props; - const stagedir = cdk.FileSystem.mkdtemp('python-bundling-'); - const hasDeps = stageDependencies(entry, stagedir); - - const depsCommand = chain([ - hasDeps ? `rsync -r ${BUNDLER_DEPENDENCIES_CACHE}/. ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}` : '', - `rsync -r . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}`, - ]); - - // Determine which dockerfile to use. When dependencies are present, we use a - // Dockerfile that can create a cacheable layer. We can't use this Dockerfile - // if there aren't dependencies or the Dockerfile will complain about missing - // sources. - const dockerfile = hasDeps - ? 'Dockerfile.dependencies' - : 'Dockerfile'; + const outputPath = outputPathSuffix? `${AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}`: AssetStaging.BUNDLING_OUTPUT_DIR; - // copy Dockerfile to workdir - fs.copyFileSync(path.join(__dirname, dockerfile), path.join(stagedir, dockerfile)); + const bundlingCommands = this.createBundlingCommand({ + entry, + inputDir: AssetStaging.BUNDLING_INPUT_DIR, + outputDir: outputPath, + }); - const defaultImage = cdk.DockerImage.fromBuild(stagedir, { + const defaultImage = DockerImage.fromBuild(path.join(__dirname, '../lib'), { buildArgs: { IMAGE: runtime.bundlingImage.image, }, platform: architecture.dockerPlatform, - file: dockerfile, }); this.image = props.image ?? defaultImage; - this.command = ['bash', '-c', depsCommand]; + this.command = ['bash', '-c', chain(bundlingCommands)]; } -} - -/** - * Checks to see if the `entry` directory contains a type of dependency that - * we know how to install. - */ -export function stageDependencies(entry: string, stagedir: string): boolean { - const prefixes = [ - 'Pipfile', - 'pyproject', - 'poetry', - 'requirements.txt', - ]; - - let found = false; - for (const file of fs.readdirSync(entry)) { - for (const prefix of prefixes) { - if (file.startsWith(prefix)) { - fs.copyFileSync(path.join(entry, file), path.join(stagedir, file)); - found = true; - } - } + private createBundlingCommand(options: BundlingCommandOptions): string[] { + const packaging = Packaging.fromEntry(options.entry); + let bundlingCommands: string[] = []; + // bundlingCommands.push(packaging.installCommand ?? ''); + bundlingCommands.push(packaging.exportCommand ?? ''); + if (packaging.dependenciesFile) { + bundlingCommands.push(`python -m pip install -r ${DependenciesFile.PIP} -t ${options.outputDir}`); + }; + bundlingCommands.push(`cp -R ${options.inputDir} ${options.outputDir}`); + return bundlingCommands; } +} - return found; +interface BundlingCommandOptions { + readonly entry: string; + readonly inputDir: string; + readonly outputDir: string; } +/** + * Chain commands + */ function chain(commands: string[]): string { return commands.filter(c => !!c).join(' && '); } From d9b306ef15564da18d858c79a6f6a3a74e42fb13 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 23:02:41 -0800 Subject: [PATCH 06/42] test: Add tests for `Packaging` --- .../aws-lambda-python/lib/bundling.ts | 2 +- .../@aws-cdk/aws-lambda-python/lib/index.ts | 1 + .../aws-lambda-python/lib/packaging.ts | 14 ++++---- .../aws-lambda-python/test/packaging.test.ts | 34 +++++++++++++++++++ 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/packaging.test.ts diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 913f5218fdcba..8f6384a366cc1 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -106,7 +106,7 @@ export class Bundling implements BundlingOptions { const { entry, runtime, architecture, outputPathSuffix } = props; - const outputPath = outputPathSuffix? `${AssetStaging.BUNDLING_OUTPUT_DIR}/${outputPathSuffix}`: AssetStaging.BUNDLING_OUTPUT_DIR; + const outputPath = path.join(AssetStaging.BUNDLING_OUTPUT_DIR, outputPathSuffix ?? ''); const bundlingCommands = this.createBundlingCommand({ entry, diff --git a/packages/@aws-cdk/aws-lambda-python/lib/index.ts b/packages/@aws-cdk/aws-lambda-python/lib/index.ts index 5459e812abb91..b4b275881c68a 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/index.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/index.ts @@ -1,2 +1,3 @@ export * from './function'; export * from './layer'; +export * from './packaging'; diff --git a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts index 71e490974b66c..3c26c41b1ee20 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts @@ -8,26 +8,26 @@ export enum DependenciesFile { NONE = '' } -interface PackagingProps { - dependenciesFile: DependenciesFile; - exportCommand?: string; +export interface PackagingProps { + readonly dependenciesFile: DependenciesFile; + readonly exportCommand?: string; } export class Packaging { - public static PIP = new Packaging({ + public static readonly PIP = new Packaging({ dependenciesFile: DependenciesFile.PIP, }); - public static PIPENV = new Packaging({ + public static readonly PIPENV = new Packaging({ dependenciesFile: DependenciesFile.PIPENV, // By default, pipenv creates a virtualenv in `/.local`, so we force it to create one in the package directory. // At the end, we remove the virtualenv to avoid creating a duplicate copy in the Lambda package. exportCommand: `PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > ${DependenciesFile.PIP} && rm -rf .venv`, }); - public static POETRY = new Packaging({ + public static readonly POETRY = new Packaging({ dependenciesFile: DependenciesFile.POETRY, exportCommand: `poetry export --with-credentials --format ${DependenciesFile.PIP} --output ${DependenciesFile.PIP}`, }); - public static NONE = new Packaging({ dependenciesFile: DependenciesFile.NONE }); + public static readonly NONE = new Packaging({ dependenciesFile: DependenciesFile.NONE }); public static fromEntry(entry: string): Packaging { if (fs.existsSync(path.join(entry, DependenciesFile.PIPENV))) { diff --git a/packages/@aws-cdk/aws-lambda-python/test/packaging.test.ts b/packages/@aws-cdk/aws-lambda-python/test/packaging.test.ts new file mode 100644 index 0000000000000..5cedd42b941bc --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/packaging.test.ts @@ -0,0 +1,34 @@ +import * as path from 'path'; +import { Packaging } from '../lib/packaging'; + +test('Packging with no dependencies', () => { + const entry = path.join(__dirname, 'lambda-handler-nodeps'); + const packaging = Packaging.fromEntry(entry); + + // pip packaging identified. + expect(packaging).toEqual(Packaging.NONE); +}); + +test('Packging with requirements.txt', () => { + const entry = path.join(__dirname, 'lambda-handler'); + const packaging = Packaging.fromEntry(entry); + + // pip packaging identified. + expect(packaging).toEqual(Packaging.PIP); +}); + +test('Packging with pipenv', () => { + const entry = path.join(__dirname, 'lambda-handler-pipenv'); + const packaging = Packaging.fromEntry(entry); + + // pip packaging identified. + expect(packaging).toEqual(Packaging.PIPENV); +}); + +test('Packging with poetry', () => { + const entry = path.join(__dirname, 'lambda-handler-poetry'); + const packaging = Packaging.fromEntry(entry); + + // pip packaging identified. + expect(packaging).toEqual(Packaging.POETRY); +}); From a4a2febc4aec3f9a3decbc194e8abe011bc5e75f Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 23:53:51 -0800 Subject: [PATCH 07/42] test: Add, update bundling tests --- .../aws-lambda-python/test/bundling.test.ts | 70 +++++++++++-------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index cbc384aec599c..cc8213d5aaa2e 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -1,8 +1,7 @@ -import * as fs from 'fs'; import * as path from 'path'; import { Architecture, Code, Runtime } from '@aws-cdk/aws-lambda'; -import { DockerImage, FileSystem } from '@aws-cdk/core'; -import { stageDependencies, Bundling } from '../lib/bundling'; +import { DockerImage } from '@aws-cdk/core'; +import { Bundling } from '../lib/bundling'; jest.spyOn(Code, 'fromAsset'); jest.spyOn(DockerImage, 'fromBuild'); @@ -30,7 +29,6 @@ test('Bundling a function without dependencies', () => { entry: entry, runtime: Runtime.PYTHON_3_7, architecture: Architecture.X86_64, - outputPathSuffix: '.', }); // Correctly bundles @@ -38,12 +36,12 @@ test('Bundling a function without dependencies', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r . /asset-output/.', + 'cp -R /asset-input /asset-output', ], }), })); - expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(/python-bundling/), expect.objectContaining({ + expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(path.join(__dirname, '../lib')), expect.objectContaining({ buildArgs: expect.objectContaining({ IMAGE: expect.stringMatching(/build-python/), }), @@ -51,13 +49,12 @@ test('Bundling a function without dependencies', () => { })); }); -test('Bundling a function with requirements.txt installed', () => { +test('Bundling a function with requirements.txt', () => { const entry = path.join(__dirname, 'lambda-handler'); Bundling.bundle({ entry: entry, runtime: Runtime.PYTHON_3_7, architecture: Architecture.X86_64, - outputPathSuffix: '.', }); // Correctly bundles @@ -65,7 +62,7 @@ test('Bundling a function with requirements.txt installed', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r /var/dependencies/. /asset-output/. && rsync -r . /asset-output/.', + 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input /asset-output', ], }), })); @@ -77,7 +74,6 @@ test('Bundling Python 2.7 with requirements.txt installed', () => { entry: entry, runtime: Runtime.PYTHON_2_7, architecture: Architecture.X86_64, - outputPathSuffix: '.', }); // Correctly bundles with requirements.txt pip installed @@ -85,7 +81,7 @@ test('Bundling Python 2.7 with requirements.txt installed', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r /var/dependencies/. /asset-output/. && rsync -r . /asset-output/.', + 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input /asset-output', ], }), })); @@ -105,7 +101,7 @@ test('Bundling a layer with dependencies', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r /var/dependencies/. /asset-output/python && rsync -r . /asset-output/python', + 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', ], }), })); @@ -125,30 +121,48 @@ test('Bundling a python code layer', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r . /asset-output/python', + 'cp -R /asset-input /asset-output/python', ], }), })); }); +test('Bundling a function with pipenv dependencies', () => { + const entry = path.join(__dirname, 'lambda-handler-pipenv'); -describe('Dependency detection', () => { - test.each(['Pipfile', 'poetry.lock', 'requirements.txt'])('detect dependency %p', filename => { - // GIVEN - const sourcedir = FileSystem.mkdtemp('source-'); - const stagedir = FileSystem.mkdtemp('stage-'); - fs.writeFileSync(path.join(sourcedir, filename), 'dummy!'); + Bundling.bundle({ + entry: path.join(entry, '.'), + runtime: Runtime.PYTHON_3_9, + architecture: Architecture.X86_64, + outputPathSuffix: 'python', + }); + + expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({ + bundling: expect.objectContaining({ + command: [ + 'bash', '-c', + 'PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > requirements.txt && rm -rf .venv && python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', + ], + }), + })); +}); - // WHEN - const found = stageDependencies(sourcedir, stagedir); +test('Bundling a function with poetry dependencies', () => { + const entry = path.join(__dirname, 'lambda-handler-poetry'); - // THEN - expect(found).toBeTruthy(); - expect(fs.existsSync(path.join(stagedir, filename))).toBeTruthy(); + Bundling.bundle({ + entry: path.join(entry, '.'), + runtime: Runtime.PYTHON_3_9, + architecture: Architecture.X86_64, + outputPathSuffix: 'python', }); - test('No known dependencies', () => { - const sourcedir = FileSystem.mkdtemp('source-'); - expect(stageDependencies(sourcedir, '/dummy')).toEqual(false); - }); + expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({ + bundling: expect.objectContaining({ + command: [ + 'bash', '-c', + 'poetry export --with-credentials --format requirements.txt --output requirements.txt && python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', + ], + }), + })); }); From b0d9432fd5db49a1d8887deb0a71d13de1f3aa4b Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 23:54:11 -0800 Subject: [PATCH 08/42] test: Add, update function, layer tests --- packages/@aws-cdk/aws-lambda-python/test/function.test.ts | 2 -- packages/@aws-cdk/aws-lambda-python/test/layer.test.ts | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 940404b0b5cd6..0c450ac51194b 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -52,7 +52,6 @@ test('PythonFunction with defaults', () => { expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ entry: expect.stringMatching(/aws-lambda-python\/test\/lambda-handler$/), - outputPathSuffix: '.', })); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { @@ -70,7 +69,6 @@ test('PythonFunction with index in a subdirectory', () => { expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ entry: expect.stringMatching(/aws-lambda-python\/test\/lambda-handler-sub$/), - outputPathSuffix: '.', })); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { diff --git a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts index 501f2a27c696b..ec357df8e1410 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { Runtime } from '@aws-cdk/aws-lambda'; import { Stack } from '@aws-cdk/core'; -import { stageDependencies, Bundling } from '../lib/bundling'; +import { Bundling } from '../lib/bundling'; import { PythonLayerVersion } from '../lib/layer'; jest.mock('../lib/bundling', () => { @@ -23,8 +23,6 @@ jest.mock('../lib/bundling', () => { }; }); -const hasDependenciesMock = (stageDependencies as jest.Mock); - let stack: Stack; beforeEach(() => { stack = new Stack(); @@ -32,8 +30,6 @@ beforeEach(() => { }); test('Bundling a layer from files', () => { - hasDependenciesMock.mockReturnValue(false); - const entry = path.join(__dirname, 'test/lambda-handler-project'); new PythonLayerVersion(stack, 'layer', { entry, From 4e7868f90adfd1031e60acb345bf25557ef2d5b7 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Fri, 24 Dec 2021 23:54:54 -0800 Subject: [PATCH 09/42] fix: Remove integ test that isn't applicable --- ...unction.requirements.removed.expected.json | 110 ------------------ .../integ.function.requirements.removed.ts | 69 ----------- 2 files changed, 179 deletions(-) delete mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.expected.json delete mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.ts diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.expected.json deleted file mode 100644 index 7cfe2de877c4a..0000000000000 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.expected.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "Resources": { - "functionServiceRoleEF216095": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - ] - } - ] - } - }, - "functionF19B1A04": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": { - "Ref": "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaS3Bucket954AFCD2" - }, - "S3Key": { - "Fn::Join": [ - "", - [ - { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "||", - { - "Ref": "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaS3VersionKeyDC672869" - } - ] - } - ] - }, - { - "Fn::Select": [ - 1, - { - "Fn::Split": [ - "||", - { - "Ref": "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaS3VersionKeyDC672869" - } - ] - } - ] - } - ] - ] - } - }, - "Role": { - "Fn::GetAtt": [ - "functionServiceRoleEF216095", - "Arn" - ] - }, - "Handler": "index.handler", - "Runtime": "python3.9" - }, - "DependsOn": [ - "functionServiceRoleEF216095" - ] - } - }, - "Parameters": { - "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaS3Bucket954AFCD2": { - "Type": "String", - "Description": "S3 bucket for asset \"50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfa\"" - }, - "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaS3VersionKeyDC672869": { - "Type": "String", - "Description": "S3 key for asset version \"50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfa\"" - }, - "AssetParameters50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfaArtifactHash06BB4065": { - "Type": "String", - "Description": "Artifact hash for asset \"50b2fdbf0e4a082a383b55e783825b1158810c097a57717d8acb11b2e2db0bfa\"" - } - }, - "Outputs": { - "Function": { - "Value": { - "Ref": "functionF19B1A04" - } - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.ts deleted file mode 100644 index ca0b62aceb950..0000000000000 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.requirements.removed.ts +++ /dev/null @@ -1,69 +0,0 @@ -/// !cdk-integ pragma:ignore-assets -import * as fs from 'fs'; -import * as os from 'os'; -import * as path from 'path'; -import { Runtime } from '@aws-cdk/aws-lambda'; -import { App, CfnOutput, Stack, StackProps } from '@aws-cdk/core'; -import { Construct, ConstructOrder } from 'constructs'; -import * as lambda from '../lib'; - -/* - * Stack verification steps: - * aws lambda invoke --function-name --invocation-type Event --payload $(base64 <<<'"OK"') response.json - */ - -class TestStack extends Stack { - public readonly dependenciesAssetHash: string; - - constructor(scope: Construct, id: string, props?: StackProps) { - super(scope, id, props); - - const fn = new lambda.PythonFunction(this, 'function', { - entry: workDir, - runtime: Runtime.PYTHON_3_9, - }); - - new CfnOutput(this, 'Function', { - value: fn.functionName, - }); - - // Find the asset hash of the dependencies - this.dependenciesAssetHash = (fn.node.findAll(ConstructOrder.POSTORDER) - .find(c => c.node.path.endsWith('Code')) as any) - .assetHash; - } -} - -// This is a special integration test that synths twice to show that docker -// picks up a change in requirements.txt - -// Create a working directory for messing around with requirements.txt -const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cdk-integ')); -fs.copyFileSync(path.join(__dirname, 'lambda-handler', 'index.py'), path.join(workDir, 'index.py')); -const requirementsTxtPath = path.join(workDir, 'requirements.txt'); - -// Write a requirements.txt with an extraneous dependency (colorama) -const beforeDeps = 'certifi==2020.6.20\nchardet==3.0.4\nidna==2.10\nurllib3==1.26.7\nrequests==2.26.0\nPillow==8.4.0\ncolorama==0.4.3\n'; -fs.writeFileSync(requirementsTxtPath, beforeDeps); - -// Synth the first time -const app = new App(); -const stack1 = new TestStack(app, 'cdk-integ-lambda-python-requirements-removed1'); -app.synth(); - -// Then, write a requirements.txt without the extraneous dependency and synth again -const afterDeps = 'certifi==2020.6.20\nchardet==3.0.4\nidna==2.10\nurllib3==1.26.7\nrequests==2.26.0\nPillow==8.4.0\n'; -fs.writeFileSync(requirementsTxtPath, afterDeps); - -// Synth the same stack a second time with different requirements.txt contents -const app2 = new App(); -const stack2 = new TestStack(app2, 'cdk-integ-lambda-python-requirements-removed2'); -app2.synth(); - -if (!stack1.dependenciesAssetHash || !stack2.dependenciesAssetHash) { - throw new Error('The asset hashes are not both truthy'); -} - -if (stack1.dependenciesAssetHash === stack2.dependenciesAssetHash) { - throw new Error('Removing a dependency did not change the asset hash'); -} From 00f8bdb983c2911160dd1a35e51f9957f2a06075 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 25 Dec 2021 00:59:42 -0800 Subject: [PATCH 10/42] feat: Split, export `BundlingOptions` --- .../aws-lambda-python/lib/bundling.ts | 75 ++++--------------- .../aws-lambda-python/lib/function.ts | 71 +++++------------- .../@aws-cdk/aws-lambda-python/lib/index.ts | 2 +- .../@aws-cdk/aws-lambda-python/lib/types.ts | 62 +++++++++++++++ 4 files changed, 95 insertions(+), 115 deletions(-) create mode 100644 packages/@aws-cdk/aws-lambda-python/lib/types.ts diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 8f6384a366cc1..10196a7a92dc3 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -1,7 +1,8 @@ import * as path from 'path'; import { Architecture, AssetCode, Code, Runtime } from '@aws-cdk/aws-lambda'; -import { AssetHashType, AssetStaging, BundlingOptions, DockerImage } from '@aws-cdk/core'; +import { AssetStaging, BundlingOptions as CdkBundlingOptions, DockerImage } from '@aws-cdk/core'; import { Packaging, DependenciesFile } from './packaging'; +import { BundlingOptions } from './types'; /** * Dependency files to exclude from the asset hash. @@ -16,80 +17,29 @@ export const BUNDLER_DEPENDENCIES_CACHE = '/var/dependencies'; /** * Options for bundling */ -export interface BundlingProps { +export interface BundlingProps extends BundlingOptions { /** * Entry path */ readonly entry: string; /** - * The runtime of the lambda function + * The runtime environment. */ readonly runtime: Runtime; /** * The system architecture of the lambda function - */ - readonly architecture: Architecture; - - /** - * Output path suffix ('python' for a layer, '.' otherwise) - */ - readonly outputPathSuffix?: string; - - /** - * Docker image to use for bundling. If no options are provided, the default bundling image - * will be used. The bundling Docker image must have `rsync` installed. Dependencies will be - * copied from the image's`/var/dependencies` directory into the Lambda asset. - * @default: - the default bundling image - */ - readonly image?: DockerImage; - - /** - * Determines how asset hash is calculated. Assets will get rebuild and - * uploaded only if their hash has changed. - * - * If asset hash is set to `SOURCE` (default), then only changes to the source - * directory will cause the asset to rebuild. This means, for example, that in - * order to pick up a new dependency version, a change must be made to the - * source tree. Ideally, this can be implemented by including a dependency - * lockfile in your source tree or using fixed dependencies. * - * If the asset hash is set to `OUTPUT`, the hash is calculated after - * bundling. This means that any change in the output will cause the asset to - * be invalidated and uploaded. Bear in mind that `pip` adds timestamps to - * dependencies it installs, which implies that in this mode Python bundles - * will _always_ get rebuild and uploaded. Normally this is an anti-pattern - * since build - * - * @default AssetHashType.SOURCE By default, hash is calculated based on the - * contents of the source directory. If `assetHash` is also specified, the - * default is `CUSTOM`. This means that only updates to the source will cause - * the asset to rebuild. + * @default Architecture.X86_64 */ - readonly assetHashType?: AssetHashType; - - /** - * Specify a custom hash for this asset. If `assetHashType` is set it must - * be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will - * be SHA256 hashed and encoded as hex. The resulting hash will be the asset - * hash. - * - * NOTE: the hash is used in order to identify a specific revision of the asset, and - * used for optimizing and caching deployment activities related to this asset such as - * packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will - * need to make sure it is updated every time the asset changes, or otherwise it is - * possible that some deployments will not be invalidated. - * - * @default - based on `assetHashType` - */ - readonly assetHash?: string; + readonly architecture?: Architecture; } /** * Produce bundled Lambda asset code */ -export class Bundling implements BundlingOptions { +export class Bundling implements CdkBundlingOptions { public static bundle(options: BundlingProps): AssetCode { return Code.fromAsset(options.entry, { assetHash: options.assetHash, @@ -103,8 +53,12 @@ export class Bundling implements BundlingOptions { public readonly command: string[]; constructor(props: BundlingProps) { - - const { entry, runtime, architecture, outputPathSuffix } = props; + const { + entry, + runtime = Runtime.PYTHON_3_7, + architecture = Architecture.X86_64, outputPathSuffix, + image, + } = props; const outputPath = path.join(AssetStaging.BUNDLING_OUTPUT_DIR, outputPathSuffix ?? ''); @@ -120,9 +74,10 @@ export class Bundling implements BundlingOptions { }, platform: architecture.dockerPlatform, }); - this.image = props.image ?? defaultImage; + this.image = image ?? defaultImage; this.command = ['bash', '-c', chain(bundlingCommands)]; } + private createBundlingCommand(options: BundlingCommandOptions): string[] { const packaging = Packaging.fromEntry(options.entry); let bundlingCommands: string[] = []; diff --git a/packages/@aws-cdk/aws-lambda-python/lib/function.ts b/packages/@aws-cdk/aws-lambda-python/lib/function.ts index 640457f492d87..329eabea6b8bd 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/function.ts @@ -1,8 +1,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as lambda from '@aws-cdk/aws-lambda'; -import { AssetHashType } from '@aws-cdk/core'; +import { Function, FunctionOptions, Runtime, RuntimeFamily } from '@aws-cdk/aws-lambda'; import { Bundling } from './bundling'; +import { BundlingOptions } from './types'; + // keep this import separate from other imports to reduce chance for merge conflicts with v2-main // eslint-disable-next-line no-duplicate-imports, import/order @@ -11,7 +12,7 @@ import { Construct } from '@aws-cdk/core'; /** * Properties for a PythonFunction */ -export interface PythonFunctionProps extends lambda.FunctionOptions { +export interface PythonFunctionProps extends FunctionOptions { /** * The path to the root directory of the function. */ @@ -35,83 +36,45 @@ export interface PythonFunctionProps extends lambda.FunctionOptions { * The runtime environment. Only runtimes of the Python family are * supported. */ - readonly runtime: lambda.Runtime; - - /** - * Determines how asset hash is calculated. Assets will get rebuild and - * uploaded only if their hash has changed. - * - * If asset hash is set to `SOURCE` (default), then only changes to the source - * directory will cause the asset to rebuild. This means, for example, that in - * order to pick up a new dependency version, a change must be made to the - * source tree. Ideally, this can be implemented by including a dependency - * lockfile in your source tree or using fixed dependencies. - * - * If the asset hash is set to `OUTPUT`, the hash is calculated after - * bundling. This means that any change in the output will cause the asset to - * be invalidated and uploaded. Bear in mind that `pip` adds timestamps to - * dependencies it installs, which implies that in this mode Python bundles - * will _always_ get rebuild and uploaded. Normally this is an anti-pattern - * since build - * - * @default AssetHashType.SOURCE By default, hash is calculated based on the - * contents of the source directory. This means that only updates to the - * source will cause the asset to rebuild. - */ - readonly assetHashType?: AssetHashType; + readonly runtime?: Runtime; /** - * Specify a custom hash for this asset. If `assetHashType` is set it must - * be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will - * be SHA256 hashed and encoded as hex. The resulting hash will be the asset - * hash. - * - * NOTE: the hash is used in order to identify a specific revision of the asset, and - * used for optimizing and caching deployment activities related to this asset such as - * packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will - * need to make sure it is updated every time the asset changes, or otherwise it is - * possible that some deployments will not be invalidated. + * Bundling options to use for this function. Use this to specify custom bundling options like + * the bundling Docker image, asset hash type, custom hash, architecture, etc. * - * @default - based on `assetHashType` + * @default - Use the default bundling Docker image, with x86_64 architecture. */ - readonly assetHash?: string; + readonly bundling?: BundlingOptions; } /** * A Python Lambda function */ -export class PythonFunction extends lambda.Function { +export class PythonFunction extends Function { constructor(scope: Construct, id: string, props: PythonFunctionProps) { - if (props.runtime && props.runtime.family !== lambda.RuntimeFamily.PYTHON) { - throw new Error('Only `PYTHON` runtimes are supported.'); - } + const { index = 'index.py', handler = 'handler', runtime = Runtime.PYTHON_3_7 } = props; if (props.index && !/\.py$/.test(props.index)) { throw new Error('Only Python (.py) index files are supported.'); } - // Entry and defaults + // Entry const entry = path.resolve(props.entry); - const index = props.index ?? 'index.py'; - const resolvedIndex = path.resolve(entry, index); if (!fs.existsSync(resolvedIndex)) { throw new Error(`Cannot find index file at ${resolvedIndex}`); } - const handler = props.handler ?? 'handler'; - const runtime = props.runtime ?? lambda.Runtime.PYTHON_3_7; - const architecture = props.architecture ?? lambda.Architecture.X86_64; + if (props.runtime && props.runtime.family !== RuntimeFamily.PYTHON) { + throw new Error('Only `PYTHON` runtimes are supported.'); + } super(scope, id, { ...props, runtime, code: Bundling.bundle({ - runtime, - architecture, entry, - outputPathSuffix: '.', - assetHashType: props.assetHashType, - assetHash: props.assetHash, + runtime, + ...props.bundling, }), handler: `${index.slice(0, -3)}.${handler}`, }); diff --git a/packages/@aws-cdk/aws-lambda-python/lib/index.ts b/packages/@aws-cdk/aws-lambda-python/lib/index.ts index b4b275881c68a..891bdeae63c53 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/index.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/index.ts @@ -1,3 +1,3 @@ export * from './function'; export * from './layer'; -export * from './packaging'; +export * from './types'; diff --git a/packages/@aws-cdk/aws-lambda-python/lib/types.ts b/packages/@aws-cdk/aws-lambda-python/lib/types.ts new file mode 100644 index 0000000000000..00e9424d2d597 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/lib/types.ts @@ -0,0 +1,62 @@ +import { AssetHashType, DockerImage } from '@aws-cdk/core'; + + +/** + * Options for bundling + */ +export interface BundlingOptions { + /** + * Output path suffix ('python' for a layer, '' otherwise) + * + * @default ''' + */ + readonly outputPathSuffix?: string; + + /** + * Docker image to use for bundling. If no options are provided, the default bundling image + * will be used. The bundling Docker image must have `rsync` installed. Dependencies will be + * copied from the image's`/var/dependencies` directory into the Lambda asset. + * @default - Default bundling image. + */ + readonly image?: DockerImage; + + /** + * Determines how asset hash is calculated. Assets will get rebuild and + * uploaded only if their hash has changed. + * + * If asset hash is set to `SOURCE` (default), then only changes to the source + * directory will cause the asset to rebuild. This means, for example, that in + * order to pick up a new dependency version, a change must be made to the + * source tree. Ideally, this can be implemented by including a dependency + * lockfile in your source tree or using fixed dependencies. + * + * If the asset hash is set to `OUTPUT`, the hash is calculated after + * bundling. This means that any change in the output will cause the asset to + * be invalidated and uploaded. Bear in mind that `pip` adds timestamps to + * dependencies it installs, which implies that in this mode Python bundles + * will _always_ get rebuild and uploaded. Normally this is an anti-pattern + * since build + * + * @default AssetHashType.SOURCE By default, hash is calculated based on the + * contents of the source directory. This means that only updates to the + * source will cause the asset to rebuild. + */ + + readonly assetHashType?: AssetHashType; + + /** + * Specify a custom hash for this asset. If `assetHashType` is set it must + * be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will + * be SHA256 hashed and encoded as hex. The resulting hash will be the asset + * hash. + * + * NOTE: the hash is used in order to identify a specific revision of the asset, and + * used for optimizing and caching deployment activities related to this asset such as + * packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will + * need to make sure it is updated every time the asset changes, or otherwise it is + * possible that some deployments will not be invalidated. + * + * @default - Based on `assetHashType` + */ + readonly assetHash?: string; +} From bddeaa52957df5872cdf1e72ebf68b29851ea255 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 25 Dec 2021 00:59:56 -0800 Subject: [PATCH 11/42] test: Fix function tests --- .../@aws-cdk/aws-lambda-python/test/function.test.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 0c450ac51194b..81a9de8d5b1cf 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -110,24 +110,21 @@ test('allows specifying hash type', () => { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', - assetHashType: AssetHashType.SOURCE, - runtime: Runtime.PYTHON_3_8, + bundling: { assetHashType: AssetHashType.SOURCE }, }); new PythonFunction(stack, 'output', { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', - assetHashType: AssetHashType.OUTPUT, - runtime: Runtime.PYTHON_3_8, + bundling: { assetHashType: AssetHashType.OUTPUT }, }); new PythonFunction(stack, 'custom', { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', - assetHash: 'MY_CUSTOM_HASH', - runtime: Runtime.PYTHON_3_8, + bundling: { assetHash: 'MY_CUSTOM_HASH' }, }); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { From 21ddb3b31a94686bb62a8ae6d9a32d284755e8c7 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 25 Dec 2021 01:22:15 -0800 Subject: [PATCH 12/42] test: Add bundling, integ test for custom Docker image --- .../aws-lambda-python/test/bundling.test.ts | 23 ++++ .../integ.function.custom-build.expected.json | 113 ++++++++++++++++++ .../test/integ.function.custom-build.ts | 29 +++++ .../lambda-handler-custom-build/Dockerfile | 3 + .../test/lambda-handler-custom-build/index.py | 11 ++ .../requirements.txt | 9 ++ 6 files changed, 188 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts create mode 100644 packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/Dockerfile create mode 100644 packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/index.py create mode 100644 packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/requirements.txt diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index cc8213d5aaa2e..886604104b2e6 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -166,3 +166,26 @@ test('Bundling a function with poetry dependencies', () => { }), })); }); + +test('Bundling a function with custom bundling image', () => { + const entry = path.join(__dirname, 'lambda-handler-custom-build'); + + Bundling.bundle({ + entry: path.join(entry, '.'), + runtime: Runtime.PYTHON_3_9, + architecture: Architecture.X86_64, + outputPathSuffix: 'python', + image: DockerImage.fromBuild(path.join(entry)), + }); + + expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({ + bundling: expect.objectContaining({ + command: [ + 'bash', '-c', + 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', + ], + }), + })); + + expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(entry)); +}); diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json new file mode 100644 index 0000000000000..6ca89444b408d --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json @@ -0,0 +1,113 @@ +{ + "Resources": { + "myhandlerServiceRole77891068": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "myhandlerD202FA8E": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "myhandlerServiceRole77891068", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "python3.7" + }, + "DependsOn": [ + "myhandlerServiceRole77891068" + ] + } + }, + "Parameters": { + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "Type": "String", + "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "Type": "String", + "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "Type": "String", + "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + } + }, + "Outputs": { + "FunctionArn": { + "Value": { + "Fn::GetAtt": [ + "myhandlerD202FA8E", + "Arn" + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts new file mode 100644 index 0000000000000..24839ac40988d --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts @@ -0,0 +1,29 @@ +import * as path from 'path'; +import { App, CfnOutput, DockerImage, Stack, StackProps } from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import * as lambda from '../lib'; + +/* + * Stack verification steps: + * * aws lambda invoke --function-name --invocation-type Event --payload '"OK"' response.json + */ + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + const entry = path.join(__dirname, 'lambda-handler-custom-build'); + const fn = new lambda.PythonFunction(this, 'my_handler', { + entry: entry, + bundling: { image: DockerImage.fromBuild(path.join(entry)) }, + }); + + new CfnOutput(this, 'FunctionArn', { + value: fn.functionArn, + }); + } +} + +const app = new App(); +new TestStack(app, 'cdk-integ-lambda-custom-build'); +app.synth(); diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/Dockerfile b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/Dockerfile new file mode 100644 index 0000000000000..4204e9e4e3bd8 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/Dockerfile @@ -0,0 +1,3 @@ +FROM public.ecr.aws/sam/build-python3.7 + +CMD [ "python" ] diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/index.py b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/index.py new file mode 100644 index 0000000000000..c033f37560534 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/index.py @@ -0,0 +1,11 @@ +import requests +from PIL import Image + +def handler(event, context): + response = requests.get('https://a0.awsstatic.com/main/images/logos/aws_smile-header-desktop-en-white_59x35.png', stream=True) + img = Image.open(response.raw) + + print(response.status_code) + print(img.size) + + return response.status_code diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/requirements.txt b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/requirements.txt new file mode 100644 index 0000000000000..c636db83b8c9e --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-custom-build/requirements.txt @@ -0,0 +1,9 @@ +# Lock versions of pip packages +certifi==2020.6.20 +chardet==3.0.4 +idna==2.10 +urllib3==1.26.7 +# Requests used by this lambda +requests==2.26.0 +# Pillow 6.x so that python 2.7 and 3.x can both use this fixture +Pillow==8.4.0 From f8e2a14141edcffd12a572b076b5157d36d7f809 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sat, 25 Dec 2021 01:23:03 -0800 Subject: [PATCH 13/42] test: Ignore reqs.txt generated during test runs --- .../aws-lambda-python/test/lambda-handler-pipenv/.gitignore | 2 ++ .../aws-lambda-python/test/lambda-handler-poetry/.gitignore | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/lambda-handler-pipenv/.gitignore create mode 100644 packages/@aws-cdk/aws-lambda-python/test/lambda-handler-poetry/.gitignore diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-pipenv/.gitignore b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-pipenv/.gitignore new file mode 100644 index 0000000000000..c7f1fd9a72f12 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-pipenv/.gitignore @@ -0,0 +1,2 @@ +# Generated during tests. +requirements.txt diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-poetry/.gitignore b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-poetry/.gitignore new file mode 100644 index 0000000000000..c7f1fd9a72f12 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-poetry/.gitignore @@ -0,0 +1,2 @@ +# Generated during tests. +requirements.txt From a6ddd7e3503faf7432e20568d7489c3986a1e827 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 18:04:21 -0800 Subject: [PATCH 14/42] fix: Add default value for `Runtime` --- packages/@aws-cdk/aws-lambda-python/lib/function.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/function.ts b/packages/@aws-cdk/aws-lambda-python/lib/function.ts index 329eabea6b8bd..9de4881134e30 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/function.ts @@ -35,6 +35,8 @@ export interface PythonFunctionProps extends FunctionOptions { /** * The runtime environment. Only runtimes of the Python family are * supported. + * + * @default Runtime.PYTHON_3_7 */ readonly runtime?: Runtime; From 8fadde51d2a5b43d37f2b7b5d01fbe4aa3442049 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:00:31 -0800 Subject: [PATCH 15/42] feat: Add bundling as an option for `PythonLayerVersion` --- packages/@aws-cdk/aws-lambda-python/lib/layer.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/layer.ts b/packages/@aws-cdk/aws-lambda-python/lib/layer.ts index 529e93ba4151d..d0b9bc6d0f529 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/layer.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/layer.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import * as lambda from '@aws-cdk/aws-lambda'; import { Bundling } from './bundling'; +import { BundlingOptions } from './types'; // keep this import separate from other imports to reduce chance for merge conflicts with v2-main // eslint-disable-next-line no-duplicate-imports, import/order @@ -18,7 +19,7 @@ export interface PythonLayerVersionProps extends lambda.LayerVersionOptions { /** * The runtimes compatible with the python layer. * - * @default - All runtimes are supported. + * @default - Only Python 3.7 is supported. */ readonly compatibleRuntimes?: lambda.Runtime[]; @@ -27,6 +28,13 @@ export interface PythonLayerVersionProps extends lambda.LayerVersionOptions { * @default [Architecture.X86_64] */ readonly compatibleArchitectures?: lambda.Architecture[]; + /** + * Bundling options to use for this function. Use this to specify custom bundling options like + * the bundling Docker image, asset hash type, custom hash, architecture, etc. + * + * @default - Use the default bundling Docker image, with x86_64 architecture. + */ + readonly bundling?: BundlingOptions; } /** @@ -59,6 +67,7 @@ export class PythonLayerVersion extends lambda.LayerVersion { runtime, architecture, outputPathSuffix: 'python', + ...props.bundling, }), }); } From 435776466f74ba338b83075431a9b3198261846d Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:01:17 -0800 Subject: [PATCH 16/42] test: Add tests for validating custom images are used for functions and layers --- .../aws-lambda-python/test/function.test.ts | 21 ++++++++++++++++--- .../aws-lambda-python/test/layer.test.ts | 16 +++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 81a9de8d5b1cf..935d4ceffaff7 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -1,13 +1,14 @@ +import * as path from 'path'; import { Template } from '@aws-cdk/assertions'; import { Code, Runtime } from '@aws-cdk/aws-lambda'; -import { AssetHashType, AssetOptions, Stack } from '@aws-cdk/core'; +import { AssetHashType, DockerImage, Stack } from '@aws-cdk/core'; import { PythonFunction } from '../lib'; -import { Bundling } from '../lib/bundling'; +import { Bundling, BundlingProps } from '../lib/bundling'; jest.mock('../lib/bundling', () => { return { Bundling: { - bundle: jest.fn().mockImplementation((options: AssetOptions): Code => { + bundle: jest.fn().mockImplementation((options: BundlingProps): Code => { const mockObjectKey = (() => { const hashType = options.assetHashType ?? (options.assetHash ? 'custom' : 'source'); switch (hashType) { @@ -148,3 +149,17 @@ test('allows specifying hash type', () => { }, }); }); + +test('Allows use of custom bundling image', () => { + const entry = path.join(__dirname, 'lambda-handler-custom-build'); + const image = DockerImage.fromBuild(path.join(entry)); + + new PythonFunction(stack, 'function', { + entry, + bundling: { image }, + }); + + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ + image, + })); +}); diff --git a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts index ec357df8e1410..a254e82d48af6 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/layer.test.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import { Runtime } from '@aws-cdk/aws-lambda'; -import { Stack } from '@aws-cdk/core'; +import { DockerImage, Stack } from '@aws-cdk/core'; import { Bundling } from '../lib/bundling'; import { PythonLayerVersion } from '../lib/layer'; @@ -49,3 +49,17 @@ test('Fails when bundling a layer for a runtime not supported', () => { }); }).toThrow(/PYTHON.*support/); }); + +test('Allows use of custom bundling image', () => { + const entry = path.join(__dirname, 'lambda-handler-custom-build'); + const image = DockerImage.fromBuild(path.join(entry)); + + new PythonLayerVersion(stack, 'layer', { + entry, + bundling: { image }, + }); + + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ + image, + })); +}); From 1c55a1149b86f7265c872492295c625fe65299dc Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:19:14 -0800 Subject: [PATCH 17/42] docs: Add documentation for bundling, update for packaging --- packages/@aws-cdk/aws-lambda-python/README.md | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index ca173c7bb5666..99e5372a8a1a9 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -27,7 +27,7 @@ Define a `PythonFunction`: ```ts new lambda.PythonFunction(this, 'MyFunction', { entry: '/path/to/my/function', // required - runtime: Runtime.PYTHON_3_6, // required + runtime: Runtime.PYTHON_3_6, // optional, defaults to Python 3.7 index: 'my_index.py', // optional, defaults to 'index.py' handler: 'my_exported_func', // optional, defaults to 'handler' }); @@ -35,21 +35,48 @@ new lambda.PythonFunction(this, 'MyFunction', { All other properties of `lambda.Function` are supported, see also the [AWS Lambda construct library](https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda). -## Module Dependencies +## Python Layer -If `requirements.txt` or `Pipfile` exists at the entry path, the construct will handle installing -all required modules in a [Lambda compatible Docker container](https://gallery.ecr.aws/sam/build-python3.7) -according to the `runtime` and with the Docker platform based on the target architecture of the Lambda function. +Define a `PythonLayerVersion`: + +```ts +new lambda.PythonLayerVersion(this, 'MyLayer', { + entry: '/path/to/my/layer', // point this to your library's directory +}) +``` + +A layer can also be used as a part of a `PythonFunction`: + +```ts +new lambda.PythonFunction(this, 'MyFunction', { + entry: '/path/to/my/function', + runtime: Runtime.PYTHON_3_6, + layers: [ + new lambda.PythonLayerVersion(this, 'MyLayer', { + entry: '/path/to/my/layer', // point this to your library's directory + }), + ], +}); +``` + +## Packaging + +If `requirements.txt`, `Pipfile` or `poetry.lock` exists at the entry path, the construct will handle installing all required modules in a [Lambda compatible Docker container](https://gallery.ecr.aws/sam/build-python3.7) according to the `runtime` and with the Docker platform based on the target architecture of the Lambda function. Python bundles are only recreated and published when a file in a source directory has changed. Therefore (and as a general best-practice), it is highly recommended to commit a lockfile with a -list of all transitive dependencies and their exact versions. -This will ensure that when any dependency version is updated, the bundle asset is recreated and uploaded. +list of all transitive dependencies and their exact versions. This will ensure that when any dependency version is updated, the bundle asset is recreated and uploaded. -To that end, we recommend using [`pipenv`] or [`poetry`] which has lockfile support. +To that end, we recommend using [`pipenv`] or [`poetry`] which have lockfile support. -[`pipenv`]: https://pipenv-fork.readthedocs.io/en/latest/basics.html#example-pipfile-lock -[`poetry`]: https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +- [`pipenv`](https://pipenv-fork.readthedocs.io/en/latest/basics.html#example-pipfile-lock) +- [`poetry`](https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control) + +Packaging is executed using the `Packaging` class, which: +1. Infers the packaging type based on the files present. +2. If it sees a `Pipfile` or a `poetry.lock` file, it exports it to a compatible `requirements.txt` file with credentials (if they're available in the source files or in the bundling container). +3. Installs dependencies using `pip`. +4. Copies the dependencies into an asset that is bundled for the Lambda package. **Lambda with a requirements.txt** @@ -73,8 +100,8 @@ To that end, we recommend using [`pipenv`] or [`poetry`] which has lockfile supp ```plaintext . ├── lambda_function.py # exports a function named 'handler' -├── pyproject.toml # has to be present at the entry path -├── poetry.lock # your poetry lock file +├── pyproject.toml # your poetry project definition +├── poetry.lock # your poetry lock file has to be present at the entry path ``` **Lambda Layer Support** @@ -83,14 +110,18 @@ You may create a python-based lambda layer with `PythonLayerVersion`. If `Python or `Pipfile` or `poetry.lock` with the associated `pyproject.toml` at the entry path, then `PythonLayerVersion` will include the dependencies inline with your code in the layer. -```ts -new lambda.PythonFunction(this, 'MyFunction', { - entry: '/path/to/my/function', - runtime: Runtime.PYTHON_3_6, - layers: [ - new lambda.PythonLayerVersion(this, 'MyLayer', { - entry: '/path/to/my/layer', // point this to your library's directory - }), - ], +## Custom Bundling + +Custom bundling can be performed by using custom Docker images for bundling dependencies. If using a custom Docker image for bundling, the dependencies are installed with `pip`, `pipenv` or `poetry` by using the `Packaging` class. + +A different bundling Docker image that is in the same directory as the function can be specified as: + + ```ts +const entry = '/path/to/function'; +const image = DockerImage.fromBuild(entry); + +new PythonFunction(stack, 'function', { + entry, + bundling: { image }, }); ``` From ef448b995792eb2888945abbb8c42a3e27a79161 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:26:29 -0800 Subject: [PATCH 18/42] docs: Add docstrings for `Packaging` --- packages/@aws-cdk/aws-lambda-python/README.md | 1 + .../aws-lambda-python/lib/packaging.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 99e5372a8a1a9..e30690d7e956a 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -73,6 +73,7 @@ To that end, we recommend using [`pipenv`] or [`poetry`] which have lockfile sup - [`poetry`](https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control) Packaging is executed using the `Packaging` class, which: + 1. Infers the packaging type based on the files present. 2. If it sees a `Pipfile` or a `poetry.lock` file, it exports it to a compatible `requirements.txt` file with credentials (if they're available in the source files or in the bundling container). 3. Installs dependencies using `pip`. diff --git a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts index 3c26c41b1ee20..3a4e85176bb27 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts @@ -9,24 +9,49 @@ export enum DependenciesFile { } export interface PackagingProps { + /** + * Dependency file for the type of packaging. + */ readonly dependenciesFile: DependenciesFile; + /** + * Command to export the dependencies into a pip-compatible `requirements.txt` format. + * + * @default ''' + */ readonly exportCommand?: string; } export class Packaging { + + /** + * Standard packaging with `pip`. + */ public static readonly PIP = new Packaging({ dependenciesFile: DependenciesFile.PIP, }); + + /** + * Packaging with `pipenv`. + */ public static readonly PIPENV = new Packaging({ dependenciesFile: DependenciesFile.PIPENV, // By default, pipenv creates a virtualenv in `/.local`, so we force it to create one in the package directory. // At the end, we remove the virtualenv to avoid creating a duplicate copy in the Lambda package. exportCommand: `PIPENV_VENV_IN_PROJECT=1 pipenv lock -r > ${DependenciesFile.PIP} && rm -rf .venv`, }); + + /** + * Packaging with `poetry`. + */ public static readonly POETRY = new Packaging({ dependenciesFile: DependenciesFile.POETRY, + // Export dependencies with credentials avaiable in the bundling image. exportCommand: `poetry export --with-credentials --format ${DependenciesFile.PIP} --output ${DependenciesFile.PIP}`, }); + + /** + * No dependencies or packaging. + */ public static readonly NONE = new Packaging({ dependenciesFile: DependenciesFile.NONE }); public static fromEntry(entry: string): Packaging { From f92fb6574b0fab6fa4938d54fa539a97520a1cb3 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:40:00 -0800 Subject: [PATCH 19/42] fix: Specify default `outputPathSuffix` --- packages/@aws-cdk/aws-lambda-python/lib/bundling.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 10196a7a92dc3..5ca0015714fe0 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -55,12 +55,13 @@ export class Bundling implements CdkBundlingOptions { constructor(props: BundlingProps) { const { entry, - runtime = Runtime.PYTHON_3_7, - architecture = Architecture.X86_64, outputPathSuffix, + runtime, + architecture = Architecture.X86_64, + outputPathSuffix = '', image, } = props; - const outputPath = path.join(AssetStaging.BUNDLING_OUTPUT_DIR, outputPathSuffix ?? ''); + const outputPath = path.join(AssetStaging.BUNDLING_OUTPUT_DIR, outputPathSuffix); const bundlingCommands = this.createBundlingCommand({ entry, From 5da5804be66e1c4f70bc334e3b266f10377450dc Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:42:52 -0800 Subject: [PATCH 20/42] fix: Remove commented line --- packages/@aws-cdk/aws-lambda-python/lib/bundling.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 5ca0015714fe0..b767a2401f8be 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -82,7 +82,6 @@ export class Bundling implements CdkBundlingOptions { private createBundlingCommand(options: BundlingCommandOptions): string[] { const packaging = Packaging.fromEntry(options.entry); let bundlingCommands: string[] = []; - // bundlingCommands.push(packaging.installCommand ?? ''); bundlingCommands.push(packaging.exportCommand ?? ''); if (packaging.dependenciesFile) { bundlingCommands.push(`python -m pip install -r ${DependenciesFile.PIP} -t ${options.outputDir}`); From 90a87179931b6fb7ffe426bcc483962f01a837aa Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:46:33 -0800 Subject: [PATCH 21/42] fix: docstring for `image` --- packages/@aws-cdk/aws-lambda-python/lib/types.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/types.ts b/packages/@aws-cdk/aws-lambda-python/lib/types.ts index 00e9424d2d597..b9aa3ca99a325 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/types.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/types.ts @@ -14,8 +14,9 @@ export interface BundlingOptions { /** * Docker image to use for bundling. If no options are provided, the default bundling image - * will be used. The bundling Docker image must have `rsync` installed. Dependencies will be - * copied from the image's`/var/dependencies` directory into the Lambda asset. + * will be used. Dependencies will be installed using the default packaging commands + * and copied over from into the Lambda asset. + * * @default - Default bundling image. */ readonly image?: DockerImage; From efceeb862ea142e7eb0354d7d3b320d96eb20842 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 22:48:50 -0800 Subject: [PATCH 22/42] test: Verify bundling image was used --- packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index 886604104b2e6..44dca36f5e61a 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -169,17 +169,19 @@ test('Bundling a function with poetry dependencies', () => { test('Bundling a function with custom bundling image', () => { const entry = path.join(__dirname, 'lambda-handler-custom-build'); + const image = DockerImage.fromBuild(path.join(entry)); Bundling.bundle({ entry: path.join(entry, '.'), runtime: Runtime.PYTHON_3_9, architecture: Architecture.X86_64, outputPathSuffix: 'python', - image: DockerImage.fromBuild(path.join(entry)), + image, }); expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({ bundling: expect.objectContaining({ + image, command: [ 'bash', '-c', 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', From a9f6d8270b68c957bb7a57f066d22d73b7fb4fc1 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Mon, 27 Dec 2021 23:23:38 -0800 Subject: [PATCH 23/42] docs: Fix example to match fixture --- packages/@aws-cdk/aws-lambda-python/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index e30690d7e956a..2712ca2b78f02 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -121,7 +121,7 @@ A different bundling Docker image that is in the same directory as the function const entry = '/path/to/function'; const image = DockerImage.fromBuild(entry); -new PythonFunction(stack, 'function', { +new lambda.PythonFunction(this, 'function', { entry, bundling: { image }, }); From 2ecff2ca33c906fd2ed663edd672b62852d8770b Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Tue, 28 Dec 2021 16:51:34 -0800 Subject: [PATCH 24/42] fix: Add `DockerImage` to default fixture --- packages/@aws-cdk/aws-lambda-python/rosetta/default.ts-fixture | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/rosetta/default.ts-fixture b/packages/@aws-cdk/aws-lambda-python/rosetta/default.ts-fixture index 516396a167e8e..44f98d42e9d09 100644 --- a/packages/@aws-cdk/aws-lambda-python/rosetta/default.ts-fixture +++ b/packages/@aws-cdk/aws-lambda-python/rosetta/default.ts-fixture @@ -1,6 +1,6 @@ // Fixture with packages imported, but nothing else import { Construct } from 'constructs'; -import { Stack } from '@aws-cdk/core'; +import { DockerImage, Stack } from '@aws-cdk/core'; import { Runtime } from '@aws-cdk/aws-lambda'; import * as lambda from '@aws-cdk/aws-lambda-python'; From bf0dc2ed3ff850e54b80ca5a709d48e602abafcd Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Tue, 28 Dec 2021 22:58:11 -0800 Subject: [PATCH 25/42] test: Add response to nodeps test --- .../aws-lambda-python/test/lambda-handler-nodeps/index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-nodeps/index.py b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-nodeps/index.py index f118d0551afb8..d7b2ce8db00e9 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-nodeps/index.py +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-nodeps/index.py @@ -1,2 +1,5 @@ +from http import HTTPStatus + def handler(event, context): print('No dependencies') + return HTTPStatus.OK.value From 8253cd906828273241c7abde9456e6b1d6a23b84 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Tue, 28 Dec 2021 22:59:16 -0800 Subject: [PATCH 26/42] test: Complete `custom_index.py` to match nodeps --- .../test/lambda-handler-sub/inner/custom_index.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-sub/inner/custom_index.py b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-sub/inner/custom_index.py index e69de29bb2d1d..d7b2ce8db00e9 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-sub/inner/custom_index.py +++ b/packages/@aws-cdk/aws-lambda-python/test/lambda-handler-sub/inner/custom_index.py @@ -0,0 +1,5 @@ +from http import HTTPStatus + +def handler(event, context): + print('No dependencies') + return HTTPStatus.OK.value From 3c457be67dfedd3a004cefb1b6df2d57b4989ab7 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Tue, 28 Dec 2021 23:01:42 -0800 Subject: [PATCH 27/42] test: Add integration test for no dependencies --- .../test/integ.function.nodeps.expected.json | 113 ++++++++++++++++++ .../test/integ.function.nodeps.ts | 27 +++++ 2 files changed, 140 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json new file mode 100644 index 0000000000000..6ca89444b408d --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json @@ -0,0 +1,113 @@ +{ + "Resources": { + "myhandlerServiceRole77891068": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "myhandlerD202FA8E": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "myhandlerServiceRole77891068", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "python3.7" + }, + "DependsOn": [ + "myhandlerServiceRole77891068" + ] + } + }, + "Parameters": { + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "Type": "String", + "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "Type": "String", + "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "Type": "String", + "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + } + }, + "Outputs": { + "FunctionArn": { + "Value": { + "Fn::GetAtt": [ + "myhandlerD202FA8E", + "Arn" + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts new file mode 100644 index 0000000000000..6e2acb7fd50c6 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts @@ -0,0 +1,27 @@ +import * as path from 'path'; +import { App, CfnOutput, Stack, StackProps } from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import * as lambda from '../lib'; + +/* + * Stack verification steps: + * * aws lambda invoke --function-name --invocation-type Event --payload '"OK"' response.json + */ + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + const fn = new lambda.PythonFunction(this, 'my_handler', { + entry: path.join(__dirname, 'lambda-handler-nodeps'), + }); + + new CfnOutput(this, 'FunctionArn', { + value: fn.functionArn, + }); + } +} + +const app = new App(); +new TestStack(app, 'cdk-integ-lambda-python'); +app.synth(); From 889fc19862c3aa97a5e04c4f690dfd6358e3b52f Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Tue, 28 Dec 2021 23:02:30 -0800 Subject: [PATCH 28/42] test: Add integration test for sub-dir package --- .../test/integ.function.sub.expected.json | 113 ++++++++++++++++++ .../test/integ.function.sub.ts | 29 +++++ 2 files changed, 142 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json new file mode 100644 index 0000000000000..a7e3071c852a1 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -0,0 +1,113 @@ +{ + "Resources": { + "myhandlerServiceRole77891068": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "myhandlerD202FA8E": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + } + ] + } + ] + } + ] + ] + } + }, + "Role": { + "Fn::GetAtt": [ + "myhandlerServiceRole77891068", + "Arn" + ] + }, + "Handler": "inner/custom_index.custom_handler", + "Runtime": "python3.7" + }, + "DependsOn": [ + "myhandlerServiceRole77891068" + ] + } + }, + "Parameters": { + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "Type": "String", + "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "Type": "String", + "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + }, + "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "Type": "String", + "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + } + }, + "Outputs": { + "FunctionArn": { + "Value": { + "Fn::GetAtt": [ + "myhandlerD202FA8E", + "Arn" + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts new file mode 100644 index 0000000000000..34021b646dd8c --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts @@ -0,0 +1,29 @@ +import * as path from 'path'; +import { App, CfnOutput, Stack, StackProps } from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import * as lambda from '../lib'; + +/* + * Stack verification steps: + * * aws lambda invoke --function-name --invocation-type Event --payload '"OK"' response.json + */ + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + const fn = new lambda.PythonFunction(this, 'my_handler', { + entry: path.join(__dirname, 'lambda-handler-sub'), + index: 'inner/custom_index.py', + handler: 'custom_handler', + }); + + new CfnOutput(this, 'FunctionArn', { + value: fn.functionArn, + }); + } +} + +const app = new App(); +new TestStack(app, 'cdk-integ-lambda-python'); +app.synth(); From eb4cb42878fd03098a489374b3debab12b4a83c4 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 12:14:23 -0800 Subject: [PATCH 29/42] test: Update integration tests' expected output --- .../integ.function.custom-build.expected.json | 18 +++++----- .../test/integ.function.expected.json | 18 +++++----- .../test/integ.function.nodeps.expected.json | 18 +++++----- .../test/integ.function.pipenv.expected.json | 36 +++++++++---------- .../test/integ.function.poetry.expected.json | 36 +++++++++---------- .../test/integ.function.project.expected.json | 36 +++++++++---------- .../test/integ.function.py38.expected.json | 18 +++++----- .../test/integ.function.sub.expected.json | 18 +++++----- .../test/integ.function.vpc.expected.json | 18 +++++----- 9 files changed, 108 insertions(+), 108 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json index 6ca89444b408d..7a428ec7e3074 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + "Ref": "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfS3BucketE101E6F9" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfS3VersionKey08D4E5C6" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfS3VersionKey08D4E5C6" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfS3BucketE101E6F9": { "Type": "String", - "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 bucket for asset \"623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abf\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfS3VersionKey08D4E5C6": { "Type": "String", - "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 key for asset version \"623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abf\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "AssetParameters623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abfArtifactHash2D0E1467": { "Type": "String", - "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "Artifact hash for asset \"623127c548bfba764c605bdc57770784dee3a4e8255ae2ad2590a2f5d42e7abf\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json index ed3d577fb40a3..d2a4f753d27f1 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684": { "Type": "String", - "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 bucket for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6": { "Type": "String", - "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 key for asset version \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75ArtifactHashBFA30B46": { "Type": "String", - "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "Artifact hash for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json index 6ca89444b408d..cbf89b966bcef 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3BucketF119340A" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3BucketF119340A": { "Type": "String", - "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 bucket for asset \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88": { "Type": "String", - "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 key for asset version \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3ArtifactHash0A5FD8A8": { "Type": "String", - "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "Artifact hash for asset \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json index dc2c5477be700..cb51e84f2e306 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7S3BucketBE0FA4A0" + "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3Bucket89DCD690" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7S3VersionKeyD39BB444" + "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7S3VersionKeyD39BB444" + "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100S3Bucket6E69F943" + "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3Bucket86058F77" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100S3VersionKey8350D955" + "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100S3VersionKey8350D955" + "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7S3BucketBE0FA4A0": { + "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3Bucket89DCD690": { "Type": "String", - "Description": "S3 bucket for asset \"227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7\"" + "Description": "S3 bucket for asset \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" }, - "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7S3VersionKeyD39BB444": { + "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5": { "Type": "String", - "Description": "S3 key for asset version \"227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7\"" + "Description": "S3 key for asset version \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" }, - "AssetParameters227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7ArtifactHash7E65B893": { + "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edArtifactHashED05F90B": { "Type": "String", - "Description": "Artifact hash for asset \"227b633cde31e51b833da8292d24ce0b348ba0a616dda185e8da6e0d37ff65f7\"" + "Description": "Artifact hash for asset \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" }, - "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100S3Bucket6E69F943": { + "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3Bucket86058F77": { "Type": "String", - "Description": "S3 bucket for asset \"02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100\"" + "Description": "S3 bucket for asset \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" }, - "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100S3VersionKey8350D955": { + "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E": { "Type": "String", - "Description": "S3 key for asset version \"02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100\"" + "Description": "S3 key for asset version \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" }, - "AssetParameters02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100ArtifactHashFBCF65DE": { + "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaArtifactHashCCBDBD02": { "Type": "String", - "Description": "Artifact hash for asset \"02c6c3394cc8925c65f92837c1ff8d5db16f412453a6247ffaace60e6335d100\"" + "Description": "Artifact hash for asset \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json index 0ed5358e2c8c3..fe9daf58098b6 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302S3Bucket19CB0678" + "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3Bucket24D73433" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302S3VersionKeyA2FCDE76" + "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302S3VersionKeyA2FCDE76" + "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebS3Bucket07693CB5" + "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3Bucket9F939AE9" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebS3VersionKey453B45DF" + "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebS3VersionKey453B45DF" + "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302S3Bucket19CB0678": { + "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3Bucket24D73433": { "Type": "String", - "Description": "S3 bucket for asset \"8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302\"" + "Description": "S3 bucket for asset \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" }, - "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302S3VersionKeyA2FCDE76": { + "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB": { "Type": "String", - "Description": "S3 key for asset version \"8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302\"" + "Description": "S3 key for asset version \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" }, - "AssetParameters8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302ArtifactHash7948D306": { + "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416ArtifactHashD37CDC18": { "Type": "String", - "Description": "Artifact hash for asset \"8c61809cd22a99ff94bd310623c77431c57aa8b1fd4d2ccfb76488d63a663302\"" + "Description": "Artifact hash for asset \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" }, - "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebS3Bucket07693CB5": { + "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3Bucket9F939AE9": { "Type": "String", - "Description": "S3 bucket for asset \"40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9eb\"" + "Description": "S3 bucket for asset \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" }, - "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebS3VersionKey453B45DF": { + "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1": { "Type": "String", - "Description": "S3 key for asset version \"40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9eb\"" + "Description": "S3 key for asset version \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" }, - "AssetParameters40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9ebArtifactHashFAE08C9B": { + "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633ArtifactHash5CB39B57": { "Type": "String", - "Description": "Artifact hash for asset \"40c9006277807fed5dd60eb40b6160230d1966e5a491ff67e8f502b18009d9eb\"" + "Description": "Artifact hash for asset \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json index 0e27a16d95cac..4040e0bcf7fdc 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json @@ -5,7 +5,7 @@ "Properties": { "Content": { "S3Bucket": { - "Ref": "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137S3Bucket3B546DC9" + "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3BucketBF92BC4F" }, "S3Key": { "Fn::Join": [ @@ -18,7 +18,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137S3VersionKeyAB88DB86" + "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF" } ] } @@ -31,7 +31,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137S3VersionKeyAB88DB86" + "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF" } ] } @@ -82,7 +82,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856S3Bucket091DB419" + "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3Bucket908D0A13" }, "S3Key": { "Fn::Join": [ @@ -95,7 +95,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856S3VersionKey635CFDCB" + "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249" } ] } @@ -108,7 +108,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856S3VersionKey635CFDCB" + "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249" } ] } @@ -138,29 +138,29 @@ } }, "Parameters": { - "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137S3Bucket3B546DC9": { + "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3BucketBF92BC4F": { "Type": "String", - "Description": "S3 bucket for asset \"e6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137\"" + "Description": "S3 bucket for asset \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" }, - "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137S3VersionKeyAB88DB86": { + "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF": { "Type": "String", - "Description": "S3 key for asset version \"e6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137\"" + "Description": "S3 key for asset version \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" }, - "AssetParameterse6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137ArtifactHashE6CFFE39": { + "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51ArtifactHash84215402": { "Type": "String", - "Description": "Artifact hash for asset \"e6dde8a412edfc6d967ce7244c803ebd6523ebc30b4c5562919028c6edf8f137\"" + "Description": "Artifact hash for asset \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" }, - "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856S3Bucket091DB419": { + "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3Bucket908D0A13": { "Type": "String", - "Description": "S3 bucket for asset \"4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856\"" + "Description": "S3 bucket for asset \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" }, - "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856S3VersionKey635CFDCB": { + "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249": { "Type": "String", - "Description": "S3 key for asset version \"4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856\"" + "Description": "S3 key for asset version \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" }, - "AssetParameters4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856ArtifactHashB70D4FAA": { + "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857ArtifactHash5B4A643B": { "Type": "String", - "Description": "Artifact hash for asset \"4364b96840104e125d2c47166f8bada01e9a636f3c23d4cddf681c685d494856\"" + "Description": "Artifact hash for asset \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json index 41d154158be8a..6cd9c620422c3 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dS3Bucket2D6AE647" + "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3Bucket20C4C05F" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dS3VersionKeyF8CA384F" + "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dS3VersionKeyF8CA384F" + "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dS3Bucket2D6AE647": { + "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3Bucket20C4C05F": { "Type": "String", - "Description": "S3 bucket for asset \"c3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526d\"" + "Description": "S3 bucket for asset \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" }, - "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dS3VersionKeyF8CA384F": { + "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561": { "Type": "String", - "Description": "S3 key for asset version \"c3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526d\"" + "Description": "S3 key for asset version \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" }, - "AssetParametersc3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526dArtifactHash8B92B092": { + "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403ArtifactHashC4DFF988": { "Type": "String", - "Description": "Artifact hash for asset \"c3efdfac6089b6c2ee8dce3aac310085091823af614fce0fb5e42799930f526d\"" + "Description": "Artifact hash for asset \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json index a7e3071c852a1..3c44a7a33990e 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE" + "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3Bucket58F8CFE2" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1" + "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3Bucket07AE44EE": { + "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3Bucket58F8CFE2": { "Type": "String", - "Description": "S3 bucket for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 bucket for asset \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374S3VersionKey01F8F2A1": { + "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73": { "Type": "String", - "Description": "S3 key for asset version \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "S3 key for asset version \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" }, - "AssetParameters3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374ArtifactHashDECBC32A": { + "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997ArtifactHash66313509": { "Type": "String", - "Description": "Artifact hash for asset \"3dc2f7b8375fbf383f44eb8f798d324f60d516946c9f829fca3c5f747f973374\"" + "Description": "Artifact hash for asset \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json index 99705bba839a3..c71510a0e5fef 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json @@ -296,7 +296,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2S3Bucket383ED51E" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684" }, "S3Key": { "Fn::Join": [ @@ -309,7 +309,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2S3VersionKeyA520554C" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" } ] } @@ -322,7 +322,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2S3VersionKeyA520554C" + "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" } ] } @@ -368,17 +368,17 @@ } }, "Parameters": { - "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2S3Bucket383ED51E": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684": { "Type": "String", - "Description": "S3 bucket for asset \"fc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2\"" + "Description": "S3 bucket for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" }, - "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2S3VersionKeyA520554C": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6": { "Type": "String", - "Description": "S3 key for asset version \"fc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2\"" + "Description": "S3 key for asset version \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" }, - "AssetParametersfc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2ArtifactHashB863A6ED": { + "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75ArtifactHashBFA30B46": { "Type": "String", - "Description": "Artifact hash for asset \"fc7bfbf72c74b955f7bc25d2bb123c0eeec9557cda17481146d51672768907b2\"" + "Description": "Artifact hash for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" } }, "Outputs": { From 5bfaf9d17c15662b1298676a1f0745644d316b97 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 12:56:36 -0800 Subject: [PATCH 30/42] fix: Resolve handler to improve sub-dir handling fixes https://github.com/aws/aws-cdk/issues/15391 --- packages/@aws-cdk/aws-lambda-python/lib/function.ts | 6 ++++-- packages/@aws-cdk/aws-lambda-python/test/function.test.ts | 2 +- .../aws-lambda-python/test/integ.function.sub.expected.json | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/function.ts b/packages/@aws-cdk/aws-lambda-python/lib/function.ts index 9de4881134e30..680c9cf845265 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/function.ts @@ -14,7 +14,7 @@ import { Construct } from '@aws-cdk/core'; */ export interface PythonFunctionProps extends FunctionOptions { /** - * The path to the root directory of the function. + * Path to the source of the function or the location for dependencies. */ readonly entry: string; @@ -70,6 +70,8 @@ export class PythonFunction extends Function { throw new Error('Only `PYTHON` runtimes are supported.'); } + const resolvedHandler =`${index.slice(0, -3)}.${handler}`.replace('/', '.'); + super(scope, id, { ...props, runtime, @@ -78,7 +80,7 @@ export class PythonFunction extends Function { runtime, ...props.bundling, }), - handler: `${index.slice(0, -3)}.${handler}`, + handler: resolvedHandler, }); } } diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 935d4ceffaff7..3a28f276ec7ad 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -73,7 +73,7 @@ test('PythonFunction with index in a subdirectory', () => { })); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { - Handler: 'inner/custom_index.custom_handler', + Handler: 'inner.custom_index.custom_handler', }); }); diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json index 3c44a7a33990e..35e40ea2f0cc6 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -78,7 +78,7 @@ "Arn" ] }, - "Handler": "inner/custom_index.custom_handler", + "Handler": "inner.custom_index.custom_handler", "Runtime": "python3.7" }, "DependsOn": [ From 7d64d5382ef679ea3921efd5d2bbe6d9e403b43b Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 13:43:32 -0800 Subject: [PATCH 31/42] test: Update integration tests' expected templates --- .../test/integ.function.expected.json | 18 +++++----- .../test/integ.function.nodeps.expected.json | 18 +++++----- .../test/integ.function.pipenv.expected.json | 36 +++++++++---------- .../test/integ.function.poetry.expected.json | 36 +++++++++---------- .../test/integ.function.project.expected.json | 36 +++++++++---------- .../test/integ.function.py38.expected.json | 18 +++++----- .../test/integ.function.sub.expected.json | 18 +++++----- .../test/integ.function.vpc.expected.json | 18 +++++----- 8 files changed, 99 insertions(+), 99 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json index d2a4f753d27f1..e960f14f53da4 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86": { "Type": "String", - "Description": "S3 bucket for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "S3 bucket for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" }, - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474": { "Type": "String", - "Description": "S3 key for asset version \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "S3 key for asset version \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" }, - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75ArtifactHashBFA30B46": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402ArtifactHash11FBB0E2": { "Type": "String", - "Description": "Artifact hash for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "Artifact hash for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json index cbf89b966bcef..2b1c84cef6129 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3BucketF119340A" + "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3BucketCD347728" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88" + "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88" + "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3BucketF119340A": { + "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3BucketCD347728": { "Type": "String", - "Description": "S3 bucket for asset \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" + "Description": "S3 bucket for asset \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" }, - "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3S3VersionKey306B0B88": { + "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6": { "Type": "String", - "Description": "S3 key for asset version \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" + "Description": "S3 key for asset version \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" }, - "AssetParameters70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3ArtifactHash0A5FD8A8": { + "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007ArtifactHash2FFAE491": { "Type": "String", - "Description": "Artifact hash for asset \"70b16c0b326ebdb072ce0ce0e3956b5cef04d2cd7effb449869410f4792d22e3\"" + "Description": "Artifact hash for asset \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json index cb51e84f2e306..5c42d2d8ae039 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3Bucket89DCD690" + "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3Bucket28DE965C" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5" + "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5" + "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3Bucket86058F77" + "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3Bucket30B96187" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E" + "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E" + "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3Bucket89DCD690": { + "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3Bucket28DE965C": { "Type": "String", - "Description": "S3 bucket for asset \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" + "Description": "S3 bucket for asset \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" }, - "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edS3VersionKeyF631C4C5": { + "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF": { "Type": "String", - "Description": "S3 key for asset version \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" + "Description": "S3 key for asset version \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" }, - "AssetParametersdd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4edArtifactHashED05F90B": { + "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834ArtifactHashB18D5756": { "Type": "String", - "Description": "Artifact hash for asset \"dd10144dc55478db76a941c5334bd190b61a71765d4feb598fad406b3ecfd4ed\"" + "Description": "Artifact hash for asset \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" }, - "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3Bucket86058F77": { + "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3Bucket30B96187": { "Type": "String", - "Description": "S3 bucket for asset \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" + "Description": "S3 bucket for asset \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" }, - "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaS3VersionKeyB3D0502E": { + "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58": { "Type": "String", - "Description": "S3 key for asset version \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" + "Description": "S3 key for asset version \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" }, - "AssetParametersf3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdebaArtifactHashCCBDBD02": { + "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fArtifactHashB538A15F": { "Type": "String", - "Description": "Artifact hash for asset \"f3ad6081e8cc32918753daa9d3b4ce660f8a89cc6303b6fb085d0b59b77cdeba\"" + "Description": "Artifact hash for asset \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json index fe9daf58098b6..be71ef8fee84f 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3Bucket24D73433" + "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3BucketA8E187C6" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB" + "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB" + "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3Bucket9F939AE9" + "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3Bucket73EC24FA" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1" + "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1" + "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3Bucket24D73433": { + "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3BucketA8E187C6": { "Type": "String", - "Description": "S3 bucket for asset \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" + "Description": "S3 bucket for asset \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" }, - "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416S3VersionKey52F0CCDB": { + "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B": { "Type": "String", - "Description": "S3 key for asset version \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" + "Description": "S3 key for asset version \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" }, - "AssetParameters755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416ArtifactHashD37CDC18": { + "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5ArtifactHash54313146": { "Type": "String", - "Description": "Artifact hash for asset \"755f662098b78df11e5a47cdf52b508480d29f88dc3e26a10fd45b3beff99416\"" + "Description": "Artifact hash for asset \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" }, - "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3Bucket9F939AE9": { + "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3Bucket73EC24FA": { "Type": "String", - "Description": "S3 bucket for asset \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" + "Description": "S3 bucket for asset \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" }, - "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633S3VersionKeyB9F7FFA1": { + "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915": { "Type": "String", - "Description": "S3 key for asset version \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" + "Description": "S3 key for asset version \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" }, - "AssetParameters57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633ArtifactHash5CB39B57": { + "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daArtifactHash08145CA8": { "Type": "String", - "Description": "Artifact hash for asset \"57afe0d7590dcde5d8cea8854024a09bed614eb70262992f3aab58fe9e803633\"" + "Description": "Artifact hash for asset \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json index 4040e0bcf7fdc..43266039f4cc1 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json @@ -5,7 +5,7 @@ "Properties": { "Content": { "S3Bucket": { - "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3BucketBF92BC4F" + "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3BucketAAE71A38" }, "S3Key": { "Fn::Join": [ @@ -18,7 +18,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF" + "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B" } ] } @@ -31,7 +31,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF" + "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B" } ] } @@ -82,7 +82,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3Bucket908D0A13" + "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3BucketE1EFB930" }, "S3Key": { "Fn::Join": [ @@ -95,7 +95,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249" + "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602" } ] } @@ -108,7 +108,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249" + "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602" } ] } @@ -138,29 +138,29 @@ } }, "Parameters": { - "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3BucketBF92BC4F": { + "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3BucketAAE71A38": { "Type": "String", - "Description": "S3 bucket for asset \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" + "Description": "S3 bucket for asset \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" }, - "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51S3VersionKeyDF6F9CFF": { + "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B": { "Type": "String", - "Description": "S3 key for asset version \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" + "Description": "S3 key for asset version \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" }, - "AssetParametersf33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51ArtifactHash84215402": { + "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537ArtifactHash2C3AFC54": { "Type": "String", - "Description": "Artifact hash for asset \"f33ee44cb3347d39bf1cf71259ec9f83d5a215f50bc91b49de07d70437ac2b51\"" + "Description": "Artifact hash for asset \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" }, - "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3Bucket908D0A13": { + "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3BucketE1EFB930": { "Type": "String", - "Description": "S3 bucket for asset \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" + "Description": "S3 bucket for asset \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" }, - "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857S3VersionKey279DD249": { + "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602": { "Type": "String", - "Description": "S3 key for asset version \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" + "Description": "S3 key for asset version \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" }, - "AssetParameters3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857ArtifactHash5B4A643B": { + "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eArtifactHash24964B69": { "Type": "String", - "Description": "Artifact hash for asset \"3d9c5894c36f2f77f0b036444e14cf5afccd5dc21f475b54a490cc0fae0eb857\"" + "Description": "Artifact hash for asset \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json index 6cd9c620422c3..12d4ff92ae339 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3Bucket20C4C05F" + "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3BucketD42EEF12" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561" + "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561" + "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3Bucket20C4C05F": { + "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3BucketD42EEF12": { "Type": "String", - "Description": "S3 bucket for asset \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" + "Description": "S3 bucket for asset \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" }, - "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403S3VersionKey9A58B561": { + "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E": { "Type": "String", - "Description": "S3 key for asset version \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" + "Description": "S3 key for asset version \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" }, - "AssetParameters0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403ArtifactHashC4DFF988": { + "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328ArtifactHash5323D356": { "Type": "String", - "Description": "Artifact hash for asset \"0d1ef3e2de566da061683025ff9c5a37fe3d71d579ea3d4a3eb106ec199a1403\"" + "Description": "Artifact hash for asset \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json index 35e40ea2f0cc6..4d8c7cd7b6871 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3Bucket58F8CFE2" + "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3Bucket5DE7143C" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73" + "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73" + "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3Bucket58F8CFE2": { + "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3Bucket5DE7143C": { "Type": "String", - "Description": "S3 bucket for asset \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" + "Description": "S3 bucket for asset \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" }, - "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997S3VersionKey84BD7D73": { + "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A": { "Type": "String", - "Description": "S3 key for asset version \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" + "Description": "S3 key for asset version \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" }, - "AssetParametersd0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997ArtifactHash66313509": { + "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095ArtifactHash7B9F443A": { "Type": "String", - "Description": "Artifact hash for asset \"d0ac5e077793c756d208df04eb91701183746739c972112bb3c7f7a0305a5997\"" + "Description": "Artifact hash for asset \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json index c71510a0e5fef..477ef1c3ef70e 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json @@ -296,7 +296,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86" }, "S3Key": { "Fn::Join": [ @@ -309,7 +309,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" } ] } @@ -322,7 +322,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6" + "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" } ] } @@ -368,17 +368,17 @@ } }, "Parameters": { - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3Bucket8E11D684": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86": { "Type": "String", - "Description": "S3 bucket for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "S3 bucket for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" }, - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75S3VersionKeyB02675E6": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474": { "Type": "String", - "Description": "S3 key for asset version \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "S3 key for asset version \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" }, - "AssetParameters5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75ArtifactHashBFA30B46": { + "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402ArtifactHash11FBB0E2": { "Type": "String", - "Description": "Artifact hash for asset \"5dd8ebc27d9e11806ba58a0a3ac38a140514912f4fdb884f6e1bc6f93b736e75\"" + "Description": "Artifact hash for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" } }, "Outputs": { From 7a03fb3c7c33574ce4e3d9c99b50c48137427f5c Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 15:28:47 -0800 Subject: [PATCH 32/42] fix: Make `runtime` required --- packages/@aws-cdk/aws-lambda-python/README.md | 15 ++++++------ .../aws-lambda-python/lib/function.ts | 23 ++++++++++--------- .../aws-lambda-python/test/function.test.ts | 4 ++++ .../integ.function.custom-build.expected.json | 2 +- .../test/integ.function.custom-build.ts | 2 ++ .../test/integ.function.nodeps.expected.json | 2 +- .../test/integ.function.nodeps.ts | 2 ++ .../test/integ.function.sub.expected.json | 2 +- .../test/integ.function.sub.ts | 2 ++ 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 2712ca2b78f02..d568007dfa9e3 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -27,7 +27,7 @@ Define a `PythonFunction`: ```ts new lambda.PythonFunction(this, 'MyFunction', { entry: '/path/to/my/function', // required - runtime: Runtime.PYTHON_3_6, // optional, defaults to Python 3.7 + runtime: Runtime.PYTHON_3_8, // required index: 'my_index.py', // optional, defaults to 'index.py' handler: 'my_exported_func', // optional, defaults to 'handler' }); @@ -37,6 +37,10 @@ All other properties of `lambda.Function` are supported, see also the [AWS Lambd ## Python Layer +You may create a python-based lambda layer with `PythonLayerVersion`. If `PythonLayerVersion` detects a `requirements.txt` +or `Pipfile` or `poetry.lock` with the associated `pyproject.toml` at the entry path, then `PythonLayerVersion` will include the dependencies inline with your code in the +layer. + Define a `PythonLayerVersion`: ```ts @@ -50,7 +54,7 @@ A layer can also be used as a part of a `PythonFunction`: ```ts new lambda.PythonFunction(this, 'MyFunction', { entry: '/path/to/my/function', - runtime: Runtime.PYTHON_3_6, + runtime: Runtime.PYTHON_3_8, layers: [ new lambda.PythonLayerVersion(this, 'MyLayer', { entry: '/path/to/my/layer', // point this to your library's directory @@ -105,12 +109,6 @@ Packaging is executed using the `Packaging` class, which: ├── poetry.lock # your poetry lock file has to be present at the entry path ``` -**Lambda Layer Support** - -You may create a python-based lambda layer with `PythonLayerVersion`. If `PythonLayerVersion` detects a `requirements.txt` -or `Pipfile` or `poetry.lock` with the associated `pyproject.toml` at the entry path, then `PythonLayerVersion` will include the dependencies inline with your code in the -layer. - ## Custom Bundling Custom bundling can be performed by using custom Docker images for bundling dependencies. If using a custom Docker image for bundling, the dependencies are installed with `pip`, `pipenv` or `poetry` by using the `Packaging` class. @@ -123,6 +121,7 @@ const image = DockerImage.fromBuild(entry); new lambda.PythonFunction(this, 'function', { entry, + runtime: Runtime.PYTHON_3_8, bundling: { image }, }); ``` diff --git a/packages/@aws-cdk/aws-lambda-python/lib/function.ts b/packages/@aws-cdk/aws-lambda-python/lib/function.ts index 680c9cf845265..7938c20219f73 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/function.ts @@ -18,6 +18,15 @@ export interface PythonFunctionProps extends FunctionOptions { */ readonly entry: string; + + /** + * The runtime environment. Only runtimes of the Python family are + * supported. + * + * @default Runtime.PYTHON_3_7 + */ + readonly runtime: Runtime; + /** * The path (relative to entry) to the index file containing the exported handler. * @@ -32,14 +41,6 @@ export interface PythonFunctionProps extends FunctionOptions { */ readonly handler?: string; - /** - * The runtime environment. Only runtimes of the Python family are - * supported. - * - * @default Runtime.PYTHON_3_7 - */ - readonly runtime?: Runtime; - /** * Bundling options to use for this function. Use this to specify custom bundling options like * the bundling Docker image, asset hash type, custom hash, architecture, etc. @@ -54,7 +55,7 @@ export interface PythonFunctionProps extends FunctionOptions { */ export class PythonFunction extends Function { constructor(scope: Construct, id: string, props: PythonFunctionProps) { - const { index = 'index.py', handler = 'handler', runtime = Runtime.PYTHON_3_7 } = props; + const { index = 'index.py', handler = 'handler', runtime } = props; if (props.index && !/\.py$/.test(props.index)) { throw new Error('Only Python (.py) index files are supported.'); } @@ -66,12 +67,12 @@ export class PythonFunction extends Function { throw new Error(`Cannot find index file at ${resolvedIndex}`); } + const resolvedHandler =`${index.slice(0, -3)}.${handler}`.replace('/', '.'); + if (props.runtime && props.runtime.family !== RuntimeFamily.PYTHON) { throw new Error('Only `PYTHON` runtimes are supported.'); } - const resolvedHandler =`${index.slice(0, -3)}.${handler}`.replace('/', '.'); - super(scope, id, { ...props, runtime, diff --git a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts index 3a28f276ec7ad..7eac6ad3df9ec 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/function.test.ts @@ -111,6 +111,7 @@ test('allows specifying hash type', () => { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', + runtime: Runtime.PYTHON_3_8, bundling: { assetHashType: AssetHashType.SOURCE }, }); @@ -118,6 +119,7 @@ test('allows specifying hash type', () => { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', + runtime: Runtime.PYTHON_3_8, bundling: { assetHashType: AssetHashType.OUTPUT }, }); @@ -125,6 +127,7 @@ test('allows specifying hash type', () => { entry: 'test/lambda-handler-nodeps', index: 'index.py', handler: 'handler', + runtime: Runtime.PYTHON_3_8, bundling: { assetHash: 'MY_CUSTOM_HASH' }, }); @@ -156,6 +159,7 @@ test('Allows use of custom bundling image', () => { new PythonFunction(stack, 'function', { entry, + runtime: Runtime.PYTHON_3_8, bundling: { image }, }); diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json index 7a428ec7e3074..dd78e2d129e14 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.expected.json @@ -79,7 +79,7 @@ ] }, "Handler": "index.handler", - "Runtime": "python3.7" + "Runtime": "python3.8" }, "DependsOn": [ "myhandlerServiceRole77891068" diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts index 24839ac40988d..4553b3894cc02 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.custom-build.ts @@ -1,4 +1,5 @@ import * as path from 'path'; +import { Runtime } from '@aws-cdk/aws-lambda'; import { App, CfnOutput, DockerImage, Stack, StackProps } from '@aws-cdk/core'; import { Construct } from 'constructs'; import * as lambda from '../lib'; @@ -16,6 +17,7 @@ class TestStack extends Stack { const fn = new lambda.PythonFunction(this, 'my_handler', { entry: entry, bundling: { image: DockerImage.fromBuild(path.join(entry)) }, + runtime: Runtime.PYTHON_3_8, }); new CfnOutput(this, 'FunctionArn', { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json index 2b1c84cef6129..f5bc8885d85ed 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json @@ -79,7 +79,7 @@ ] }, "Handler": "index.handler", - "Runtime": "python3.7" + "Runtime": "python3.8" }, "DependsOn": [ "myhandlerServiceRole77891068" diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts index 6e2acb7fd50c6..54d7eadd516c1 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.ts @@ -1,4 +1,5 @@ import * as path from 'path'; +import { Runtime } from '@aws-cdk/aws-lambda'; import { App, CfnOutput, Stack, StackProps } from '@aws-cdk/core'; import { Construct } from 'constructs'; import * as lambda from '../lib'; @@ -14,6 +15,7 @@ class TestStack extends Stack { const fn = new lambda.PythonFunction(this, 'my_handler', { entry: path.join(__dirname, 'lambda-handler-nodeps'), + runtime: Runtime.PYTHON_3_8, }); new CfnOutput(this, 'FunctionArn', { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json index 4d8c7cd7b6871..52a10cc25c856 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -79,7 +79,7 @@ ] }, "Handler": "inner.custom_index.custom_handler", - "Runtime": "python3.7" + "Runtime": "python3.8" }, "DependsOn": [ "myhandlerServiceRole77891068" diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts index 34021b646dd8c..769fdc0306513 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.ts @@ -1,4 +1,5 @@ import * as path from 'path'; +import { Runtime } from '@aws-cdk/aws-lambda'; import { App, CfnOutput, Stack, StackProps } from '@aws-cdk/core'; import { Construct } from 'constructs'; import * as lambda from '../lib'; @@ -16,6 +17,7 @@ class TestStack extends Stack { entry: path.join(__dirname, 'lambda-handler-sub'), index: 'inner/custom_index.py', handler: 'custom_handler', + runtime: Runtime.PYTHON_3_8, }); new CfnOutput(this, 'FunctionArn', { From 4c4b752aee7530470283386b23e11770b2f6505d Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 15:29:08 -0800 Subject: [PATCH 33/42] fix: Improve default docstring for `dependenciesFile` --- packages/@aws-cdk/aws-lambda-python/lib/packaging.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts index 3a4e85176bb27..55f9118cd3ff1 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/packaging.ts @@ -16,7 +16,7 @@ export interface PackagingProps { /** * Command to export the dependencies into a pip-compatible `requirements.txt` format. * - * @default ''' + * @default - No dependencies are exported. */ readonly exportCommand?: string; } From 1c90313ac96dff39ce3731102ca51a2b918bd1f9 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 15:38:02 -0800 Subject: [PATCH 34/42] feat: Support custom `buildArgs` --- packages/@aws-cdk/aws-lambda-python/lib/Dockerfile | 3 +++ packages/@aws-cdk/aws-lambda-python/lib/bundling.ts | 1 + packages/@aws-cdk/aws-lambda-python/lib/types.ts | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile index 26928bbbb1df4..1d4d3975a3733 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile +++ b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile @@ -3,6 +3,9 @@ ARG IMAGE=public.ecr.aws/sam/build-python3.7 FROM $IMAGE +ARG PIP_INDEX_URL +ARG PIP_EXTRA_INDEX_URL + # Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry) RUN pip install --upgrade pip RUN pip install pipenv poetry diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index b767a2401f8be..37e52ac13435b 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -71,6 +71,7 @@ export class Bundling implements CdkBundlingOptions { const defaultImage = DockerImage.fromBuild(path.join(__dirname, '../lib'), { buildArgs: { + ...props.buildArgs ?? {}, IMAGE: runtime.bundlingImage.image, }, platform: architecture.dockerPlatform, diff --git a/packages/@aws-cdk/aws-lambda-python/lib/types.ts b/packages/@aws-cdk/aws-lambda-python/lib/types.ts index b9aa3ca99a325..129487b9725db 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/types.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/types.ts @@ -21,6 +21,15 @@ export interface BundlingOptions { */ readonly image?: DockerImage; + /** + * Optional build arguments to pass to the default container. This can be used to customize + * the index URLs used for installing dependencies. + * This is not used if a custom image is provided. + * + * @default - No build arguments. + */ + readonly buildArgs?: { [key: string]: string }; + /** * Determines how asset hash is calculated. Assets will get rebuild and * uploaded only if their hash has changed. From 518c3472b623fc2f619fc9f35b4872a53e704aa7 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 15:42:37 -0800 Subject: [PATCH 35/42] test: Add custom build args test --- .../aws-lambda-python/test/bundling.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index 44dca36f5e61a..5e4cf194f5151 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -191,3 +191,19 @@ test('Bundling a function with custom bundling image', () => { expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(entry)); }); + +test('Bundling with custom build args', () => { + const entry = path.join(__dirname, 'lambda-handler'); + const testPypi = 'https://test.pypi.org/simple/'; + Bundling.bundle({ + entry: entry, + runtime: Runtime.PYTHON_3_7, + buildArgs: { PIP_INDEX_URL: testPypi }, + }); + + expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(path.join(__dirname, '../lib')), expect.objectContaining({ + buildArgs: expect.objectContaining({ + PIP_INDEX_URL: testPypi, + }), + })); +}); From f0d882a82290392caea93fe837e5d0131e1c7ab5 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 16:00:40 -0800 Subject: [PATCH 36/42] docs: Add details about build args --- packages/@aws-cdk/aws-lambda-python/README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index d568007dfa9e3..1262d378bbf78 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -111,9 +111,24 @@ Packaging is executed using the `Packaging` class, which: ## Custom Bundling -Custom bundling can be performed by using custom Docker images for bundling dependencies. If using a custom Docker image for bundling, the dependencies are installed with `pip`, `pipenv` or `poetry` by using the `Packaging` class. +Custom bundling can be performed by passing in additional build arguments that point to index URLs to private repos, or by using an entirely custom Docker images for bundling dependencies. -A different bundling Docker image that is in the same directory as the function can be specified as: +Additional build args for bundling that refer to PyPI indexes can be specified as: + +```ts +const entry = '/path/to/function'; +const image = DockerImage.fromBuild(entry); + +new PythonFunction(stack, 'function', { + entry, + runtime: Runtime.PYTHON_3_8, + bundling: { + buildArgs: { PIP_INDEX_URL: "https://your.index.url/simple/", PIP_EXTRA_INDEX_URL: "https://your.extra-index.url/simple/" }, + }, +}); +``` + +If using a custom Docker image for bundling, the dependencies are installed with `pip`, `pipenv` or `poetry` by using the `Packaging` class. A different bundling Docker image that is in the same directory as the function can be specified as: ```ts const entry = '/path/to/function'; From bc17ce44cea0cba69540de36b519aa394221f6ad Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 16:02:20 -0800 Subject: [PATCH 37/42] docs: Add example on using Code Artifact --- packages/@aws-cdk/aws-lambda-python/README.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 1262d378bbf78..8ff1f67eaf4f2 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -140,3 +140,30 @@ new lambda.PythonFunction(this, 'function', { bundling: { image }, }); ``` + +## Custom Bundling with Code Artifact + +To use a Code Artifact PyPI repo, the `PIP_INDEX_URL` for bundling the function can be customized (requires AWS CLI in the build environment): + +```ts +import { execSync } from 'child_process'; + +const entry = '/path/to/function'; +const image = DockerImage.fromBuild(entry); + +const domain = 'my-domain'; +const domainOwner = '111122223333'; +const codeArtifactAuthToken = execSync(`aws codeartifact get-authorization-token --domain ${domain} --domain-owner ${domainOwner} --query authorizationToken --output text`).toString().trim(); + +const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${stack.env?.region}.amazonaws.com/pypi/my_repo/simple/`; + +new PythonFunction(stack, 'function', { + entry, + runtime: Runtime.PYTHON_3_8, + bundling: { + buildArgs: { PIP_INDEX_URL: indexUrl }, + }, +}); +``` + +This type of an example should work for `pip` and `poetry` based dependencies, but will not work for `pipenv`. From 737618810698a4e3acc00fd1c5a0d2fe3b2f57c1 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 16:08:59 -0800 Subject: [PATCH 38/42] docs: Fix scope reference --- packages/@aws-cdk/aws-lambda-python/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 8ff1f67eaf4f2..39d4de23cb3e9 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -119,7 +119,7 @@ Additional build args for bundling that refer to PyPI indexes can be specified a const entry = '/path/to/function'; const image = DockerImage.fromBuild(entry); -new PythonFunction(stack, 'function', { +new PythonFunction(this, 'function', { entry, runtime: Runtime.PYTHON_3_8, bundling: { @@ -153,11 +153,12 @@ const image = DockerImage.fromBuild(entry); const domain = 'my-domain'; const domainOwner = '111122223333'; +const repoName = 'my_repo'; const codeArtifactAuthToken = execSync(`aws codeartifact get-authorization-token --domain ${domain} --domain-owner ${domainOwner} --query authorizationToken --output text`).toString().trim(); -const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${stack.env?.region}.amazonaws.com/pypi/my_repo/simple/`; +const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${this.stack.env?.region}.amazonaws.com/pypi/${repoName}/simple/`; -new PythonFunction(stack, 'function', { +new PythonFunction(this, 'function', { entry, runtime: Runtime.PYTHON_3_8, bundling: { From 8b701d47ecd6812222ae43f1a69109d3bbd42e4f Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 16:16:26 -0800 Subject: [PATCH 39/42] feat: Support customizing `HTTPS_PROXY` Resolves #12949, closes #13938. --- packages/@aws-cdk/aws-lambda-python/README.md | 6 +++++- packages/@aws-cdk/aws-lambda-python/lib/Dockerfile | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 39d4de23cb3e9..268761c53a3be 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -111,7 +111,11 @@ Packaging is executed using the `Packaging` class, which: ## Custom Bundling -Custom bundling can be performed by passing in additional build arguments that point to index URLs to private repos, or by using an entirely custom Docker images for bundling dependencies. +Custom bundling can be performed by passing in additional build arguments that point to index URLs to private repos, or by using an entirely custom Docker images for bundling dependencies. The build args currently supported are: + +- `PIP_INDEX_URL` +- `PIP_EXTRA_INDEX_URL` +- `HTTPS_PROXY` Additional build args for bundling that refer to PyPI indexes can be specified as: diff --git a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile index 1d4d3975a3733..462d9c645fb9f 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile +++ b/packages/@aws-cdk/aws-lambda-python/lib/Dockerfile @@ -5,6 +5,7 @@ FROM $IMAGE ARG PIP_INDEX_URL ARG PIP_EXTRA_INDEX_URL +ARG HTTPS_PROXY # Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry) RUN pip install --upgrade pip From e9cd424d1ac05bc4636966039ce083616b4d096f Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 16:25:08 -0800 Subject: [PATCH 40/42] test: Update integ tests' JSON --- .../test/integ.function.expected.json | 18 +++++----- .../test/integ.function.nodeps.expected.json | 18 +++++----- .../test/integ.function.pipenv.expected.json | 36 +++++++++---------- .../test/integ.function.poetry.expected.json | 36 +++++++++---------- .../test/integ.function.project.expected.json | 36 +++++++++---------- .../test/integ.function.py38.expected.json | 18 +++++----- .../test/integ.function.sub.expected.json | 18 +++++----- .../test/integ.function.vpc.expected.json | 18 +++++----- 8 files changed, 99 insertions(+), 99 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json index e960f14f53da4..bf6248e87c68e 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86" + "Ref": "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055S3Bucket4083148B" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" + "Ref": "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055S3VersionKey32133DD4" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" + "Ref": "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055S3VersionKey32133DD4" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86": { + "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055S3Bucket4083148B": { "Type": "String", - "Description": "S3 bucket for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "S3 bucket for asset \"13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055\"" }, - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474": { + "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055S3VersionKey32133DD4": { "Type": "String", - "Description": "S3 key for asset version \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "S3 key for asset version \"13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055\"" }, - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402ArtifactHash11FBB0E2": { + "AssetParameters13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055ArtifactHash83828A10": { "Type": "String", - "Description": "Artifact hash for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "Artifact hash for asset \"13be70bc2398416ddd6c8e123f99becf43b8b1c3d00cad2447f9f75cea39d055\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json index f5bc8885d85ed..a12a5675b097f 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.nodeps.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3BucketCD347728" + "Ref": "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201S3BucketE6A02FFC" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6" + "Ref": "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201S3VersionKey78F64422" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6" + "Ref": "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201S3VersionKey78F64422" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3BucketCD347728": { + "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201S3BucketE6A02FFC": { "Type": "String", - "Description": "S3 bucket for asset \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" + "Description": "S3 bucket for asset \"adeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201\"" }, - "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007S3VersionKey40CEE6E6": { + "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201S3VersionKey78F64422": { "Type": "String", - "Description": "S3 key for asset version \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" + "Description": "S3 key for asset version \"adeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201\"" }, - "AssetParameters89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007ArtifactHash2FFAE491": { + "AssetParametersadeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201ArtifactHash5EE39E2F": { "Type": "String", - "Description": "Artifact hash for asset \"89066eb8c4481f205da3b1389f3d01f89529e31fdc9b784d633ee1abe7282007\"" + "Description": "Artifact hash for asset \"adeacc0a6e55ff50a5243310913e886cc41725125e145a916ff3ec01369b2201\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json index 5c42d2d8ae039..80d1579481795 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.pipenv.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3Bucket28DE965C" + "Ref": "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2S3BucketC982114B" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF" + "Ref": "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2S3VersionKey6D9FF4C1" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF" + "Ref": "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2S3VersionKey6D9FF4C1" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3Bucket30B96187" + "Ref": "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427S3Bucket42FB475E" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58" + "Ref": "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427S3VersionKeyFFD26447" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58" + "Ref": "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427S3VersionKeyFFD26447" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3Bucket28DE965C": { + "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2S3BucketC982114B": { "Type": "String", - "Description": "S3 bucket for asset \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" + "Description": "S3 bucket for asset \"c850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2\"" }, - "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834S3VersionKey99B09ADF": { + "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2S3VersionKey6D9FF4C1": { "Type": "String", - "Description": "S3 key for asset version \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" + "Description": "S3 key for asset version \"c850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2\"" }, - "AssetParametersd64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834ArtifactHashB18D5756": { + "AssetParametersc850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2ArtifactHash27EECEC5": { "Type": "String", - "Description": "Artifact hash for asset \"d64dfa0bc9be87b6fc985ee1bd1c8a83dbbe38d4b248f58cdf76e7d533e6a834\"" + "Description": "Artifact hash for asset \"c850e159fa69da9edb39ca17a495c47ca137fb5ea2119efb9b01468b0a4934a2\"" }, - "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3Bucket30B96187": { + "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427S3Bucket42FB475E": { "Type": "String", - "Description": "S3 bucket for asset \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" + "Description": "S3 bucket for asset \"ebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427\"" }, - "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fS3VersionKey30716A58": { + "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427S3VersionKeyFFD26447": { "Type": "String", - "Description": "S3 key for asset version \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" + "Description": "S3 key for asset version \"ebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427\"" }, - "AssetParametersab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0fArtifactHashB538A15F": { + "AssetParametersebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427ArtifactHashCC6CC552": { "Type": "String", - "Description": "Artifact hash for asset \"ab7a7d74b2f9677e92aedab6219a35e148be4361a4fdda6a8d0368b67cbb7f0f\"" + "Description": "Artifact hash for asset \"ebc380ae5f94c7b58c30d780f064bc980ad95d026b4e753349d00efc56f40427\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json index be71ef8fee84f..868afeba6ff43 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.poetry.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3BucketA8E187C6" + "Ref": "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daS3Bucket142AE375" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B" + "Ref": "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daS3VersionKeyDC1A62D5" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B" + "Ref": "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daS3VersionKeyDC1A62D5" } ] } @@ -121,7 +121,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3Bucket73EC24FA" + "Ref": "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dS3BucketB5B7A82F" }, "S3Key": { "Fn::Join": [ @@ -134,7 +134,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915" + "Ref": "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dS3VersionKey06225DD1" } ] } @@ -147,7 +147,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915" + "Ref": "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dS3VersionKey06225DD1" } ] } @@ -172,29 +172,29 @@ } }, "Parameters": { - "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3BucketA8E187C6": { + "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daS3Bucket142AE375": { "Type": "String", - "Description": "S3 bucket for asset \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" + "Description": "S3 bucket for asset \"ab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0da\"" }, - "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5S3VersionKey38AB3C3B": { + "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daS3VersionKeyDC1A62D5": { "Type": "String", - "Description": "S3 key for asset version \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" + "Description": "S3 key for asset version \"ab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0da\"" }, - "AssetParametersc017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5ArtifactHash54313146": { + "AssetParametersab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0daArtifactHash0EF1F0C3": { "Type": "String", - "Description": "Artifact hash for asset \"c017b1fa15ca885f31b7a401f179edda9a28ddc5ba7bdb6d18f3dd817cc234a5\"" + "Description": "Artifact hash for asset \"ab7f43c80b3b659f320744f583b7bfda3605f7018c253ab2e7615cfb667cb0da\"" }, - "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3Bucket73EC24FA": { + "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dS3BucketB5B7A82F": { "Type": "String", - "Description": "S3 bucket for asset \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" + "Description": "S3 bucket for asset \"67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1d\"" }, - "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daS3VersionKey14D08915": { + "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dS3VersionKey06225DD1": { "Type": "String", - "Description": "S3 key for asset version \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" + "Description": "S3 key for asset version \"67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1d\"" }, - "AssetParameters0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38daArtifactHash08145CA8": { + "AssetParameters67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1dArtifactHash253A552F": { "Type": "String", - "Description": "Artifact hash for asset \"0a0f5d8a56b6a41a9f8b6cda42ee721bf2efdc83012c64b12d51ff1db52d38da\"" + "Description": "Artifact hash for asset \"67452e07162ae977faecaa7c71cf523f4442341f285bd53f84089624ce7fff1d\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json index 43266039f4cc1..0f96e29246a70 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.project.expected.json @@ -5,7 +5,7 @@ "Properties": { "Content": { "S3Bucket": { - "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3BucketAAE71A38" + "Ref": "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949S3BucketE93E5D2C" }, "S3Key": { "Fn::Join": [ @@ -18,7 +18,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B" + "Ref": "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949S3VersionKey13A824E8" } ] } @@ -31,7 +31,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B" + "Ref": "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949S3VersionKey13A824E8" } ] } @@ -82,7 +82,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3BucketE1EFB930" + "Ref": "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676S3Bucket9F42D72A" }, "S3Key": { "Fn::Join": [ @@ -95,7 +95,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602" + "Ref": "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676S3VersionKey37C5ED38" } ] } @@ -108,7 +108,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602" + "Ref": "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676S3VersionKey37C5ED38" } ] } @@ -138,29 +138,29 @@ } }, "Parameters": { - "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3BucketAAE71A38": { + "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949S3BucketE93E5D2C": { "Type": "String", - "Description": "S3 bucket for asset \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" + "Description": "S3 bucket for asset \"1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949\"" }, - "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537S3VersionKeyEC74EB3B": { + "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949S3VersionKey13A824E8": { "Type": "String", - "Description": "S3 key for asset version \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" + "Description": "S3 key for asset version \"1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949\"" }, - "AssetParametersdc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537ArtifactHash2C3AFC54": { + "AssetParameters1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949ArtifactHashD6269488": { "Type": "String", - "Description": "Artifact hash for asset \"dc1697d22382c29173c745259b16485ec89421f2115add1bb49a7a2ca9768537\"" + "Description": "Artifact hash for asset \"1f7d3c2f23a4820c4d01a0bce4add499802732068e570fb63c9f9ae0c2011949\"" }, - "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3BucketE1EFB930": { + "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676S3Bucket9F42D72A": { "Type": "String", - "Description": "S3 bucket for asset \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" + "Description": "S3 bucket for asset \"3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676\"" }, - "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eS3VersionKey33989602": { + "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676S3VersionKey37C5ED38": { "Type": "String", - "Description": "S3 key for asset version \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" + "Description": "S3 key for asset version \"3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676\"" }, - "AssetParameters06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717eArtifactHash24964B69": { + "AssetParameters3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676ArtifactHash74C7DB3B": { "Type": "String", - "Description": "Artifact hash for asset \"06fb22c4e3099bb25c65f4d23e7342b5390788a7a9fd8f50aa086e501641717e\"" + "Description": "Artifact hash for asset \"3164004f2e76531b3631d1b70c1bee3da1439011bf712a91211b8721868da676\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json index 12d4ff92ae339..8c028fc0afac0 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3BucketD42EEF12" + "Ref": "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6S3Bucket8DE4578D" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E" + "Ref": "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6S3VersionKey86A8985D" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E" + "Ref": "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6S3VersionKey86A8985D" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3BucketD42EEF12": { + "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6S3Bucket8DE4578D": { "Type": "String", - "Description": "S3 bucket for asset \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" + "Description": "S3 bucket for asset \"9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6\"" }, - "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328S3VersionKey5564708E": { + "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6S3VersionKey86A8985D": { "Type": "String", - "Description": "S3 key for asset version \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" + "Description": "S3 key for asset version \"9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6\"" }, - "AssetParameters7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328ArtifactHash5323D356": { + "AssetParameters9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6ArtifactHash4E095FCC": { "Type": "String", - "Description": "Artifact hash for asset \"7558e9c118e8bd06a695aae05722a86d88a8343963f6b1d5e95ba774f0853328\"" + "Description": "Artifact hash for asset \"9004e881069342d6cd7cc95689e1c51eb68f9f5d8c0bdfb0c2c52d9aa301d1d6\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json index 52a10cc25c856..fb29f895b492e 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.sub.expected.json @@ -36,7 +36,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3Bucket5DE7143C" + "Ref": "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647S3Bucket11B30F21" }, "S3Key": { "Fn::Join": [ @@ -49,7 +49,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A" + "Ref": "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647S3VersionKey1D9AFDF5" } ] } @@ -62,7 +62,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A" + "Ref": "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647S3VersionKey1D9AFDF5" } ] } @@ -87,17 +87,17 @@ } }, "Parameters": { - "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3Bucket5DE7143C": { + "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647S3Bucket11B30F21": { "Type": "String", - "Description": "S3 bucket for asset \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" + "Description": "S3 bucket for asset \"ccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647\"" }, - "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095S3VersionKey0A92875A": { + "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647S3VersionKey1D9AFDF5": { "Type": "String", - "Description": "S3 key for asset version \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" + "Description": "S3 key for asset version \"ccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647\"" }, - "AssetParametersaae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095ArtifactHash7B9F443A": { + "AssetParametersccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647ArtifactHash997AD273": { "Type": "String", - "Description": "Artifact hash for asset \"aae099a54a7a6ae974f100887ef280892eff27c6417284a4acc3674c326a3095\"" + "Description": "Artifact hash for asset \"ccd39730103b259d263418443f3d426e109312f1f147710e2e5fffc2150b8647\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json index 477ef1c3ef70e..fb5aafb8c9c75 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.vpc.expected.json @@ -296,7 +296,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86" + "Ref": "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38S3BucketF4C94740" }, "S3Key": { "Fn::Join": [ @@ -309,7 +309,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" + "Ref": "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38S3VersionKey584C9092" } ] } @@ -322,7 +322,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474" + "Ref": "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38S3VersionKey584C9092" } ] } @@ -368,17 +368,17 @@ } }, "Parameters": { - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3Bucket662B3B86": { + "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38S3BucketF4C94740": { "Type": "String", - "Description": "S3 bucket for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "S3 bucket for asset \"28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38\"" }, - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402S3VersionKey1C656474": { + "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38S3VersionKey584C9092": { "Type": "String", - "Description": "S3 key for asset version \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "S3 key for asset version \"28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38\"" }, - "AssetParameters41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402ArtifactHash11FBB0E2": { + "AssetParameters28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38ArtifactHashC0B5BADB": { "Type": "String", - "Description": "Artifact hash for asset \"41e025ad7310514de107dc6acad90544b7eeeabf19f9f51892af87e338381402\"" + "Description": "Artifact hash for asset \"28ffbbca5292e933d802ff7c495367b0d7fddab6f52a3777f67a52f14efc6b38\"" } }, "Outputs": { From 3f73b0a3542d7ae30b04dd20af13cad773fdeccc Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 17:13:04 -0800 Subject: [PATCH 41/42] docs: `PythonFunction` -> `lambda.PythonFunction` --- packages/@aws-cdk/aws-lambda-python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index 268761c53a3be..d9bc533b14488 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -123,7 +123,7 @@ Additional build args for bundling that refer to PyPI indexes can be specified a const entry = '/path/to/function'; const image = DockerImage.fromBuild(entry); -new PythonFunction(this, 'function', { +new lambda.PythonFunction(this, 'function', { entry, runtime: Runtime.PYTHON_3_8, bundling: { @@ -162,7 +162,7 @@ const codeArtifactAuthToken = execSync(`aws codeartifact get-authorization-token const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${this.stack.env?.region}.amazonaws.com/pypi/${repoName}/simple/`; -new PythonFunction(this, 'function', { +new lambda.PythonFunction(this, 'function', { entry, runtime: Runtime.PYTHON_3_8, bundling: { From 5e48214df3ea394c0e9121db2d4101e7d92d0fdb Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Wed, 29 Dec 2021 20:53:34 -0800 Subject: [PATCH 42/42] fix: Set region explicitly --- packages/@aws-cdk/aws-lambda-python/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-python/README.md b/packages/@aws-cdk/aws-lambda-python/README.md index d9bc533b14488..2a8de2d34c4de 100644 --- a/packages/@aws-cdk/aws-lambda-python/README.md +++ b/packages/@aws-cdk/aws-lambda-python/README.md @@ -158,9 +158,10 @@ const image = DockerImage.fromBuild(entry); const domain = 'my-domain'; const domainOwner = '111122223333'; const repoName = 'my_repo'; +const region = 'us-east-1'; const codeArtifactAuthToken = execSync(`aws codeartifact get-authorization-token --domain ${domain} --domain-owner ${domainOwner} --query authorizationToken --output text`).toString().trim(); -const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${this.stack.env?.region}.amazonaws.com/pypi/${repoName}/simple/`; +const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${region}.amazonaws.com/pypi/${repoName}/simple/`; new lambda.PythonFunction(this, 'function', { entry,