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(lambda-python): install rsync if necessary #9763

Merged
merged 6 commits into from
Aug 19, 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
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-lambda-python/lib/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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=amazon/aws-sam-cli-build-image-python3.7
FROM $IMAGE

# Ensure rsync is installed
RUN yum -q list installed rsync &>/dev/null || yum install -y rsync

CMD [ "python" ]
11 changes: 9 additions & 2 deletions packages/@aws-cdk/aws-lambda-python/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ export interface BundlingOptions {
* Produce bundled Lambda asset code
*/
export function bundle(options: BundlingOptions): lambda.AssetCode {
// Bundling image derived from runtime bundling image (AWS SAM docker image)
const image = cdk.BundlingDockerImage.fromAsset(__dirname, {
buildArgs: {
IMAGE: options.runtime.bundlingDockerImage.image,
},
});

let installer = options.runtime === lambda.Runtime.PYTHON_2_7 ? Installer.PIP : Installer.PIP3;

let hasRequirements = fs.existsSync(path.join(options.entry, 'requirements.txt'));

let depsCommand = chain([
hasRequirements ? `${installer} install -r requirements.txt -t ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}` : '',
`cp -au . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}`,
`rsync -r . ${cdk.AssetStaging.BUNDLING_OUTPUT_DIR}`,
]);

return lambda.Code.fromAsset(options.entry, {
bundling: {
image: options.runtime.bundlingDockerImage,
image,
command: ['bash', '-c', depsCommand],
},
});
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',
'cp -au . /asset-output',
'rsync -r . /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 && cp -au . /asset-output',
'pip3 install -r requirements.txt -t /asset-output && rsync -r . /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 && cp -au . /asset-output',
'pip install -r requirements.txt -t /asset-output && rsync -r . /asset-output',
],
}),
});
Expand Down