Skip to content

Commit

Permalink
fix(lambda-layer-node-proxy-agent): Replace use of package.json with …
Browse files Browse the repository at this point in the history
…Dockerfile command `npm install [package]@[version]` (#17078)

## Summary

This PR fixes an issue where the package.json file used in `lambda-layer-node-proxy-agent` was not being bundled into monocdk / CDK v2. This is due to limitations of Ubergen. Ubergen only copies .ts  files, README.md  files and some special .json files.

This PR:
- Removes the package.json from `packages/@aws-cdk/lambda-layer-node-proxy-agent/layer`
- Adds a step in the layer's Dockerfile to install a specific version of `proxy-agent` i.e. `npm install [package]@[version]`. This is so that we can do without the `package.json` file while still managing which version we bundle with the layer.

Fixes: #17061

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ryparker committed Oct 20, 2021
1 parent 1fa1876 commit a129046
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 14 deletions.
@@ -1,2 +1 @@
build.sh
.no-packagejson-validator
Empty file.
@@ -1,6 +1,8 @@
# base lambda image
FROM public.ecr.aws/lambda/nodejs:latest

ARG PROXY_AGENT_VERSION=5.0.0

USER root
RUN mkdir -p /opt
WORKDIR /tmp
Expand All @@ -17,8 +19,7 @@ RUN yum update -y \
#

RUN mkdir -p /opt/nodejs
COPY package.json /opt/nodejs
RUN cd /opt/nodejs && npm install
RUN cd /opt/nodejs && npm install proxy-agent@${PROXY_AGENT_VERSION}

#
# create the bundle
Expand Down

This file was deleted.

Expand Up @@ -11,8 +11,8 @@ export class NodeProxyAgentLayer extends lambda.LayerVersion {
constructor(scope: Construct, id: string) {
super(scope, id, {
code: lambda.Code.fromAsset(path.join(__dirname, 'layer.zip'), {
// we hash the package.json (it contains the tools versions) because hashing the zip is non-deterministic
assetHash: hashFile(path.join(__dirname, '..', 'layer', 'package.json')),
// we hash the Dockerfile (it contains the tools versions) because hashing the zip is non-deterministic
assetHash: hashFile(path.join(__dirname, '..', 'layer', 'Dockerfile')),
}),
description: '/opt/nodejs/node_modules/proxy-agent',
});
Expand Down

0 comments on commit a129046

Please sign in to comment.