From c5f0dec19c35b32c8db60c7b0820bdc603e7fb0b Mon Sep 17 00:00:00 2001 From: Adam Elmore Date: Thu, 30 Jul 2020 09:45:26 -0500 Subject: [PATCH] fix(aws-lambda-python): use cp instead of rsync Fixes #9349. The python 3.8 `bundlingDockerImage` (`amazon/aws-sam-cli-build-image-python3.8`) is based on `amazonlinux:2` and doesn't include `rsync`; use `cp` instead. --- .../aws-lambda-python/lib/bundling.ts | 2 +- .../aws-lambda-python/test/bundling.test.ts | 6 +- .../test/integ.function.py38.expected.json | 113 ++++++++++++++++++ .../test/integ.function.py38.ts | 28 +++++ 4 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.expected.json create mode 100644 packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.ts diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index 22cec7c841bde..53ea90723a32b 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -28,7 +28,7 @@ export function bundle(options: BundlingOptions): lambda.AssetCode { let depsCommand = chain([ hasRequirements ? `${installer} install -r requirements.txt -t ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}` : '', - `rsync -r . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}`, + `cp -au . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}`, ]); return lambda.Code.fromAsset(options.entry, { 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 492f7b3dbd890..fc03c7ae9bba8 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -21,7 +21,7 @@ test('Bundling', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'rsync -r . /asset-output', + 'cp -au . /asset-output', ], }), }); @@ -48,7 +48,7 @@ test('Bundling with requirements.txt installed', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'pip3 install -r requirements.txt -t /asset-output && rsync -r . /asset-output', + 'pip3 install -r requirements.txt -t /asset-output && cp -au . /asset-output', ], }), }); @@ -72,7 +72,7 @@ test('Bundling Python 2.7 with requirements.txt installed', () => { bundling: expect.objectContaining({ command: [ 'bash', '-c', - 'pip install -r requirements.txt -t /asset-output && rsync -r . /asset-output', + 'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output', ], }), }); 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 new file mode 100644 index 0000000000000..56d8661ab73d8 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.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": "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeS3Bucket0552B5BB" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeS3VersionKey9522AC10" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeS3VersionKey9522AC10" + } + ] + } + ] + } + ] + ] + } + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "myhandlerServiceRole77891068", + "Arn" + ] + }, + "Runtime": "python3.8" + }, + "DependsOn": [ + "myhandlerServiceRole77891068" + ] + } + }, + "Parameters": { + "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeS3Bucket0552B5BB": { + "Type": "String", + "Description": "S3 bucket for asset \"822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1ade\"" + }, + "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeS3VersionKey9522AC10": { + "Type": "String", + "Description": "S3 key for asset version \"822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1ade\"" + }, + "AssetParameters822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1adeArtifactHash3CE06D09": { + "Type": "String", + "Description": "Artifact hash for asset \"822ec544787c04e6b27b02f2408e4c322d48fbd352adb46d5aa2d6b3553a1ade\"" + } + }, + "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.py38.ts b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.ts new file mode 100644 index 0000000000000..0e6546d2ecbbb --- /dev/null +++ b/packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.ts @@ -0,0 +1,28 @@ +import * as path from 'path'; +import { Runtime } from '@aws-cdk/aws-lambda'; +import { App, CfnOutput, Construct, Stack, StackProps } from '@aws-cdk/core'; +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'), + runtime: Runtime.PYTHON_3_8, + }); + + new CfnOutput(this, 'FunctionArn', { + value: fn.functionArn, + }); + } +} + +const app = new App(); +new TestStack(app, 'cdk-integ-lambda-python-38'); +app.synth();