Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-lambda-python): use cp instead of rsync #9355

Merged
merged 4 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();