Skip to content

Commit

Permalink
Merge branch 'master' into njlynch/rds-cluster-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Aug 19, 2020
2 parents c414e4f + 6edb6e6 commit c104116
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
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

0 comments on commit c104116

Please sign in to comment.