Skip to content

Commit

Permalink
Upgrade to Node.js v16
Browse files Browse the repository at this point in the history
  • Loading branch information
janaz committed Apr 21, 2021
1 parent 8bc9453 commit 53966ff
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM node:15.14.0-buster-slim
FROM node:16.0.0-buster-slim

RUN apt-get update && apt-get install -y p7zip-full curl xz-utils gnupg && apt-get clean all
62 changes: 39 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# AWS Lambda NodeJS-15 Runtime
# AWS Lambda NodeJS-16 Runtime

AWS Lambda runtime API implemented in Node.js. The supported version is usually the latest LTS.

It's easy to use this project and build Node.js runtime that will target any version - just replace the version number in `auto/package` with your preferred one.

## Current versions

* Node.js - **15.14.0**
* aws-sdk - **2.887.0**
* Node.js - **16.0.0**
* aws-sdk - **2.889.0**

## Goals

* Provide always up-to-date Node.js execution environment.
* Provide always up-to-date Node.js execution environment as a Lambda runtime layer and a Lambda container image.
* Include the most recent `aws-cli` library.
* MAke the runtime environment compatible with the default node12.x and node14.x environments
* Make the runtime environment compatible with the default node12.x and node14.x environments

## How to install?

Expand All @@ -39,8 +39,8 @@ Deploy the runtime layer using the following command:

```bash
aws lambda publish-layer-version \
--layer-name node-15-runtime \
--description "nodejs-15.14.0 aws-cli-2.887.0" \
--layer-name node-16-runtime \
--description "nodejs-16.0.0 aws-cli-2.889.0" \
--compatible-runtimes provided \
--license-info Apache-2.0 \
--zip-file fileb://stage/layer.zip
Expand All @@ -49,14 +49,14 @@ aws lambda publish-layer-version \
The output will look like this:
```json
{
"LayerVersionArn": "arn:aws:lambda:us-east-2:356111732087:layer:node-15-runtime:1",
"Description": "nodejs-15.14.0 aws-cli-2.887.0",
"LayerVersionArn": "arn:aws:lambda:us-east-2:356111732087:layer:node-16-runtime:1",
"Description": "nodejs-16.0.0 aws-cli-2.889.0",
"CreatedDate": "2018-12-02T22:32:00.572+0000",
"LayerArn": "arn:aws:lambda:us-east-2:356111732087:layer:node-15-runtime",
"LayerArn": "arn:aws:lambda:us-east-2:356111732087:layer:node-16-runtime",
"Content": {
"CodeSize": 18104889,
"CodeSha256": "VonrpX23FWJOmE4lvhpox+9PS9kuY4sng0o0wxNTROs=",
"Location": "https://awslambda-us-east-2-layers.s3.us-east-2.amazonaws.com/snapshots/356111732087/node-15-runtime-f3415c38-d865-46b6-ae42-009985092116?......"
"Location": "https://awslambda-us-east-2-layers.s3.us-east-2.amazonaws.com/snapshots/356111732087/node-16-runtime-f3415c38-d865-46b6-ae42-009985092116?......"
},
"Version": 1,
"CompatibleRuntimes": [
Expand All @@ -72,7 +72,7 @@ You can share the layer with other AWS accounts by executing the following comma

```bash
aws lambda add-layer-version-permission \
--layer-name node-15-runtime \
--layer-name node-16-runtime \
--version-number 1 \
--principal "*" \
--statement-id publish \
Expand All @@ -84,7 +84,7 @@ Response:
```json
{
"RevisionId": "8b5b2e27-5013-4983-ac1a-9008dff90bac",
"Statement": "{\"Sid\":\"publish\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"lambda:GetLayerVersion\",\"Resource\":\"arn:aws:lambda:us-east-2:356111732087:layer:node-15-runtime:1\"}"
"Statement": "{\"Sid\":\"publish\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"lambda:GetLayerVersion\",\"Resource\":\"arn:aws:lambda:us-east-2:356111732087:layer:node-16-runtime:1\"}"
}
```

Expand All @@ -103,11 +103,11 @@ Let's assume that your lambda function is packaged as `lambda.zip` file and the
```bash
aws lambda create-function \
--region us-east-2 \
--function-name node-15-runtime-example \
--function-name node-16-runtime-example \
--zip-file fileb://lambda.zip \
--handler hello.handler \
--runtime provided \
--layers "arn:aws:lambda:us-east-2:356111732087:layer:node-15-runtime:2" \
--layers "arn:aws:lambda:us-east-2:356111732087:layer:node-16-runtime:2" \
--role arn:aws:iam::356111732087:role/lambda-role
out.txt
```
Expand All @@ -119,10 +119,10 @@ Let's assume that your lambda function is packaged as `lambda.zip` file and the
"Layers": [
{
"CodeSize": 18104889,
"Arn": "arn:aws:lambda:us-east-2:356111732087:layer:node-15-runtime:1"
"Arn": "arn:aws:lambda:us-east-2:356111732087:layer:node-16-runtime:1"
}
],
"FunctionName": "node-15-runtime-example",
"FunctionName": "node-16-runtime-example",
"LastModified": "2018-12-02T22:59:10.408+0000",
"RevisionId": "32e7e8a1-b5ba-4388-b6be-596278e36126",
"MemorySize": 128,
Expand All @@ -136,7 +136,7 @@ Let's assume that your lambda function is packaged as `lambda.zip` file and the
"CodeSha256": "shSeSmJZHv8Z0WmOAcFcHeSUGbRYRR1cFdbEudkSJHo=",
"Description": "",
"CodeSize": 340,
"FunctionArn": "arn:aws:lambda:us-east-2:356111732087:function:node-15-runtime-example",
"FunctionArn": "arn:aws:lambda:us-east-2:356111732087:function:node-16-runtime-example",
"Handler": "hello.handler"
}
```
Expand All @@ -146,7 +146,7 @@ Let's assume that your lambda function is packaged as `lambda.zip` file and the
```bash
aws lambda invoke \
--region us-east-2 \
--function-name node-15-runtime-example \
--function-name node-16-runtime-example \
--payload '{"hello":"world"}' \
output.txt
Expand All @@ -170,10 +170,7 @@ The context object is compatible with [the default node environments](https://do
* `awsRequestId` – The identifier of the invocation request.
* `logGroupName` – The log group for the function.
* `logStreamName` – The log stream for the function instance.
* `callbackWaitsForEmptyEventLoop` – Set to false to send the response right away when the callback executes, instead of waiting for the Node.js event loop to be empty. If false, any outstanding events will continue to run during the next invocation.
### Not yet supported properties
* `callbackWaitsForEmptyEventLoop` – Set to false to send the response right away when the callback executes, instead of waiting for the Node.js event loop to be empty.
* `identity` - Information about the Amazon Cognito identity that authorized the request.
* `clientContext` - Client context provided to the Lambda invoker by the client application.
Expand Down Expand Up @@ -201,3 +198,22 @@ AWS_LAMBDA_LOG_GROUP_NAME AWS_LAMBDA_LOG_STREAM_NAME|Yes|The name of the Amazon
|LD_LIBRARY_PATH|No|/lib64:/usr/lib64:$LAMBDA_RUNTIME_DIR:$LAMBDA_RUNTIME_DIR/lib:$LAMBDA_TASK_ROOT:$LAMBDA_TASK_ROOT/lib:/opt/lib|
|NODE_PATH|No|/opt/node_modules|
|AWS_LAMBDA_RUNTIME_API|Yes|(custom runtime) The host and port of the [runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html).|
## The base container image
The releases include a base Docker image that is compatible with the Lambda Container runtime and it's compatible with the Node.js Lambda runtime.
### Using the base image
The example below assumes that the Dockerfile is in the root folder of the Lambda project and there's an `index.js` file that exports the handler function called `handler`.
```Dockerfile
FROM janaz/aws-lambda-node-runtime:test-1
COPY . ${LAMBDA_TASK_ROOT}
RUN npm install
CMD ["index.handler"]
```
The image created from that `Dockerfile` should be uploaded to your ECR registry and referenced in the Lambda configuration.
2 changes: 1 addition & 1 deletion auto/package
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ex

export NODE_VERSION=15.14.0
export NODE_VERSION=16.0.0

DIR="$( cd "$( dirname "$0" )" && pwd )"

Expand Down
4 changes: 2 additions & 2 deletions auto/publish
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ us-west-2
"

TMP="deployment-$(date +%s).txt"
LAYER_NAME=node-15-runtime
LAYER_NAME=node-16-runtime
for R in $REGIONS ; do
echo "Deploying in ${R}"
docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --rm \
Expand All @@ -42,7 +42,7 @@ for R in $REGIONS ; do
lambda publish-layer-version \
--region "${R}" \
--layer-name "${LAYER_NAME}" \
--description "nodejs-15.14.0 aws-cli-2.887.0" \
--description "nodejs-16.0.0 aws-cli-2.889.0" \
--compatible-runtimes provided \
--license-info Apache-2.0 \
--zip-file fileb://stage/layer.zip
Expand Down
6 changes: 2 additions & 4 deletions container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

ARG NODE_VERSION=15.14.0
ARG AWS_SDK_VERSION=2.887.0
ARG NODE_VERSION=16.0.0
ARG AWS_SDK_VERSION=2.889.0
ARG AWS_LAMBDA_NODE_RUNTIME_VERSION=0.1.0

FROM node:${NODE_VERSION}-buster-slim
Expand All @@ -17,7 +17,5 @@ RUN mkdir ${BOOTSTRAP_DIR} && \
npm install --no-save -g aws-lambda-node-runtime@${AWS_LAMBDA_NODE_RUNTIME_VERSION}

WORKDIR ${LAMBDA_TASK_ROOT}
# COPY hello.js ${LAMBDA_TASK_ROOT}/

ENTRYPOINT ["/usr/local/bin/npx", "aws-lambda-node-runtime"]
# CMD ["hello.handler"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:
- runtime-api

runtime-api:
image: node:15.14.0-buster-slim
image: node:16.0.0-buster-slim
environment:
NPM_CONFIG_CACHE: /tmp/npm-cache
volumes:
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"dependencies": {
"aws-lambda-node-runtime": "0.1.0",
"aws-sdk": "^2.887.0"
"aws-sdk": "^2.889.0"
}
}

0 comments on commit 53966ff

Please sign in to comment.