From 37b425e387f909befa95013972d9b9daa448de17 Mon Sep 17 00:00:00 2001 From: Otavio Macedo Date: Fri, 7 Jan 2022 12:34:22 +0000 Subject: [PATCH] fix(lambda-python): asset files are generated inside the 'asset-input' folder (#18306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the asset structure from: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda5 │ └── asset-input │ ├── __init__.py │ └── app.py ``` to: ``` ├── asset.993168cfa75b295eeea55bf603340284b9be46ebc079e4965f2c16f5470efda5 │ ├── __init__.py │ └── app.py ``` Fixes https://github.com/aws/aws-cdk/issues/18301. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* (cherry picked from commit aff607a65e061ade5c3ec9e29f82fdaa8b57f638) --- .../@aws-cdk/aws-lambda-python/lib/bundling.ts | 4 ++-- .../aws-lambda-python/test/bundling.test.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 37e52ac13435b..34dd54e3eee98 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -86,8 +86,8 @@ export class Bundling implements CdkBundlingOptions { 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}`); + } + bundlingCommands.push(`cp -R ${options.inputDir}/ ${options.outputDir}`); return bundlingCommands; } } 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 5e4cf194f5151..e5f91b2ea09b8 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -36,7 +36,7 @@ test('Bundling a function without dependencies', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'cp -R /asset-input /asset-output', + 'cp -R /asset-input/ /asset-output', ], }), })); @@ -62,7 +62,7 @@ test('Bundling a function with requirements.txt', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input /asset-output', + 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input/ /asset-output', ], }), })); @@ -81,7 +81,7 @@ test('Bundling Python 2.7 with requirements.txt installed', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input /asset-output', + 'python -m pip install -r requirements.txt -t /asset-output && cp -R /asset-input/ /asset-output', ], }), })); @@ -101,7 +101,7 @@ test('Bundling a layer with dependencies', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', + 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python', ], }), })); @@ -121,7 +121,7 @@ test('Bundling a python code layer', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'cp -R /asset-input /asset-output/python', + 'cp -R /asset-input/ /asset-output/python', ], }), })); @@ -141,7 +141,7 @@ test('Bundling a function with pipenv dependencies', () => { 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', + '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', ], }), })); @@ -161,7 +161,7 @@ test('Bundling a function with poetry dependencies', () => { 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', + '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', ], }), })); @@ -184,7 +184,7 @@ test('Bundling a function with custom bundling image', () => { image, command: [ 'bash', '-c', - 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input /asset-output/python', + 'python -m pip install -r requirements.txt -t /asset-output/python && cp -R /asset-input/ /asset-output/python', ], }), }));