Skip to content

Commit

Permalink
fix(lambda-python): install rsync if necessary (aws#9763)
Browse files Browse the repository at this point in the history
Fixes aws#9704.

`aws-lambda-python` originally used `rsync` to move lambda code into `/asset-output`, but I switched to `cp` in aws#9355 to resolve aws#9349 as `rsync` isn't installed in the python3.8 sam docker image.

This change introduces a Dockerfile derived from the `bundlingDockerImage` of the runtime which installs `rsync` if it's missing.

While this feels a bit heavy-handed, I had been planning to introduce a Dockerfile to setup a working pip cache after aws#9582 lands.

I'm also happy to take a different approach if you'd prefer, @eladb. 

----

*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 misterjoshua committed Aug 19, 2020
1 parent d24d08a commit 30ad495
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-lambda-python/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function bundleLayerDependentFunction(options: BundlingOptions): lambda.AssetCod
return lambda.Code.fromAsset(entry, {
bundling: {
image: getLayerBundlerImage(options),
command: ['sh', '-c', `cp -r ${IMAGE_FUNCTION_DIR}/. /asset-output/`],
command: ['sh', '-c', `rsync -r ${IMAGE_FUNCTION_DIR}/. /asset-output/`],
},
assetHashType: cdk.AssetHashType.BUNDLE,
exclude: DEPENDENCY_EXCLUDES,
Expand All @@ -100,7 +100,7 @@ export function bundleLayer(options: BundlingOptions): lambda.AssetCode {
return lambda.Code.fromAsset(entry, {
bundling: {
image: getLayerBundlerImage(options),
command: ['sh', '-c', `cp -r ${IMAGE_LAYER_DIR}/. /asset-output/`],
command: ['sh', '-c', `rsync -r ${IMAGE_LAYER_DIR}/. /asset-output/`],
},
assetHashType: cdk.AssetHashType.BUNDLE,
exclude: DEPENDENCY_EXCLUDES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ARG FROM=amazon/aws-sam-cli-build-image-python3.7

FROM ${FROM}

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

RUN pip install pipenv

WORKDIR /var/task.function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ARG FROM=amazon/aws-sam-cli-build-image-python3.7

FROM ${FROM}

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

RUN pip install pipenv

WORKDIR /var/task.layer
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test('Bundling dependencies into a layer', () => {
expect(Code.fromAsset).toHaveBeenCalledWith('/project/folder', expect.objectContaining({
bundling: expect.objectContaining({
image: { image: MOCK_BUILD_IMAGE_ID },
command: ['sh', '-c', `cp -r ${IMAGE_LAYER_DIR}/. /asset-output/`],
command: ['sh', '-c', `rsync -r ${IMAGE_LAYER_DIR}/. /asset-output/`],
}),
assetHashType: cdk.AssetHashType.BUNDLE,
exclude: expect.arrayContaining(['*.pyc']),
Expand All @@ -158,7 +158,7 @@ test('Bundling dependencies into a layer', () => {
expect(Code.fromAsset).toHaveBeenCalledWith('/project/folder', expect.objectContaining({
bundling: expect.objectContaining({
image: { image: MOCK_BUILD_IMAGE_ID },
command: ['sh', '-c', `cp -r ${IMAGE_FUNCTION_DIR}/. /asset-output/`],
command: ['sh', '-c', `rsync -r ${IMAGE_FUNCTION_DIR}/. /asset-output/`],
}),
assetHashType: cdk.AssetHashType.BUNDLE,
exclude: expect.arrayContaining(['*.pyc']),
Expand Down

0 comments on commit 30ad495

Please sign in to comment.