Skip to content

Commit

Permalink
fix(aws-lambda-python): use cp instead of rsync (aws#9355)
Browse files Browse the repository at this point in the history
Fixes aws#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.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
adamdottv authored and Curtis Eppel committed Aug 11, 2020
1 parent e285831 commit 359b08a
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-python/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('Bundling', () => {
bundling: expect.objectContaining({
command: [
'bash', '-c',
'rsync -r . /asset-output',
'cp -au . /asset-output',
],
}),
});
Expand All @@ -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',
],
}),
});
Expand All @@ -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',
],
}),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-lambda-python/test/integ.function.py38.ts
Original file line number Diff line number Diff line change
@@ -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 <deployed fn 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();

0 comments on commit 359b08a

Please sign in to comment.