Skip to content

Commit

Permalink
feat(maintenance): add support for nodejs20.x runtime (#1790)
Browse files Browse the repository at this point in the history
* feat(maintenance): support nodejs20.x runtime

* tests(metrics): fix object ordering in tests

* build(testing): bump cdk

* build(maintenance): revert aws-cdk-lib to support nodejs14

* tests(maintenance): set runtime with family

* chore(docs): patch runtime in cdk

* chore(docs): patch runtime in cdk

* chore(maintenance): increment version in commons ahead of release
  • Loading branch information
dreamorosi committed Nov 20, 2023
1 parent 9c47362 commit 5d38256
Show file tree
Hide file tree
Showing 45 changed files with 216 additions and 241 deletions.
5 changes: 4 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.212.0/containers/javascript-node/.devcontainer/base.Dockerfile
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT="18-bullseye"
ARG VARIANT="20-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}

# This section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends bash-completion

# Install fnm to manage Node.js versions
RUN curl -fsSL https://fnm.vercel.app/install | bash -s

RUN wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip \
&& unzip aws-sam-cli-linux-x86_64.zip -d sam-installation \
&& sudo ./sam-installation/install \
Expand Down
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": {
"VARIANT": "18-bullseye"
"VARIANT": "20-bullseye"
}
},
"customizations": {
// Add the ids of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"firsttris.vscode-jest-runner",
"amazonwebservices.aws-toolkit-vscode"
"firsttris.vscode-jest-runner"
],
"vscode": {
"git.enableCommitSigning": true
Expand Down
5 changes: 3 additions & 2 deletions .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Cached Node Modules'
description: 'A simple action to cache node_modules or install them if they are not cached'
inputs:
nodeVersion: # id of input
nodeVersion: # id of input
description: 'Node.js version to use in the cache key'
default: '18'
default: '20'
build:
description: 'Whether to build the packages or not'
default: 'true'
Expand All @@ -15,6 +15,7 @@ runs:
using: "composite"
steps:
- name: Install npm
# We need to keep this npm version until we drop Node.js 16 support because Node.js 16 doesn't support npm 10
run: npm i -g npm@next-9
shell: bash
- name: Cache node modules
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "18"
node-version: "20"
cache: "npm"
- name: Setup auth tokens
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make-v2-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: '18'
node-version: '20'
cache: 'npm'
- name: Setup auth tokens
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "18"
node-version: "20"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: CDK build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "18"
node-version: "20"
cache: "npm"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/reusable-run-linting-check-and-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
NODE_ENV: dev
strategy:
matrix:
version: [16, 18]
version: [16, 18, 20]
fail-fast: false
steps:
- name: Checkout code
Expand Down Expand Up @@ -45,8 +45,8 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: 'npm'
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand All @@ -63,8 +63,8 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: 'npm'
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand All @@ -81,8 +81,8 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: 'npm'
node-version: 20
cache: "npm"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_deploy_layer_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: "18"
node-version: "20"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Download artifact
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
packages/parameters,
packages/idempotency,
]
version: [16, 18]
version: [16, 18, 20]
arch: [x86_64, arm64]
fail-fast: false
steps:
Expand All @@ -53,11 +53,11 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ matrix.version }}
node-version: '20'
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
with:
nodeVersion: ${{ matrix.version }}
nodeVersion: '20'
- name: Setup AWS credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/hydrogen
lts/iron
4 changes: 2 additions & 2 deletions docs/contributing/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ graph LR
Unless you're using the pre-configured Cloud environment, you'll need the following installed:

* [GitHub account](https://github.com/join){target="_blank" rel="nofollow"}. You'll need to be able to fork, clone, and contribute via pull request.
* [Node.js 18.x](https://nodejs.org/download/release/latest-v18.x/){target="_blank" rel="nofollow"}. The repository contains an `.nvmrc` file, so if you use tools like [nvm](https://github.com/nvm-sh/nvm#nvmrc), [fnm](https://github.com/Schniz/fnm) you can switch version quickly.
* [npm 9.x](https://www.npmjs.com/). We use it to install dependencies and manage the workspaces.
* [Node.js 20.x](https://nodejs.org/download/release/latest-v20.x/){target="_blank" rel="nofollow"}. The repository contains an `.nvmrc` file, so if you use tools like [nvm](https://github.com/nvm-sh/nvm#nvmrc), [fnm](https://github.com/Schniz/fnm) you can switch version quickly.
* [npm 10.x](https://www.npmjs.com/). We use it to install dependencies and manage the workspaces.
* [Docker](https://docs.docker.com/engine/install/){target="_blank" rel="nofollow"}. We use it to run documentation, and non-JavaScript tooling.
* [Fork the repository](https://github.com/aws-powertools/powertools-lambda-typescript/fork). You'll work against your fork of this repository.

Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ To run integration tests you'll need to set up an AWS account and obtain credent
* `npm test:e2e -ws` to run all the integration tests for all the modules sequentially
* `test:e2e:parallel` to run all the integration tests for all the modules in parallel
* `npm test:e2e -w packages/metrics` to run all the integration tests for the `metrics` module
* `npm run test:e2e:nodejs18x -w packages/metrics` to run all the integration tests for the `metrics` module using the `nodejs18x` runtime
* `npm run test:e2e:nodejs20x -w packages/metrics` to run all the integration tests for the `metrics` module using the `nodejs20x` runtime

The tests will deploy the necessary AWS resources using AWS CDK, and will run the Lambda functions using the AWS SDK. After that, the tests will verify the Lambda functions behave as expected by checking logs, metrics, traces, and other resources as needed. Finally, the tests will destroy all the AWS resources created at the beginning.

Expand Down
2 changes: 1 addition & 1 deletion docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ These settings will be used across all logs emitted:
ShoppingCartApiFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
Runtime: nodejs20.x
Environment:
Variables:
LOG_LEVEL: WARN
Expand Down
2 changes: 1 addition & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The `Metrics` utility is instantiated outside of the Lambda handler. In doing th
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs16.x
Runtime: nodejs20.x
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: orders
Expand Down
2 changes: 1 addition & 1 deletion docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The `Tracer` utility is instantiated outside of the Lambda handler. In doing thi
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs18.x
Runtime: nodejs20.x
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/batch/templates/sam/dynamodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Runtime: nodejs20.x
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/batch/templates/sam/kinesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Runtime: nodejs20.x
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/batch/templates/sam/sqs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Runtime: nodejs20.x
Tracing: Active
Environment:
Variables:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/idempotency/templates/tableCdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class IdempotencyStack extends Stack {
});

const fnHandler = new NodejsFunction(this, 'helloWorldFunction', {
runtime: Runtime.NODEJS_18_X,
runtime: Runtime.NODEJS_20_X,
handler: 'handler',
entry: 'src/index.ts',
environment: {
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/idempotency/templates/tableSam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: python3.11
Runtime: nodejs20.x
Handler: app.py
Policies:
- Statement:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/idempotency/templates/tableTerraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "aws_dynamodb_table" "IdempotencyTable" {
resource "aws_lambda_function" "IdempotencyFunction" {
function_name = "IdempotencyFunction"
role = aws_iam_role.IdempotencyFunctionRole.arn
runtime = "nodejs18.x"
runtime = "nodejs20.x"
handler = "index.handler"
filename = "lambda.zip"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ While we support Amazon DynamoDB as a persistance layer out of the box, you need


???+ note
This utility supports **[AWS SDK for JavaScript v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/){target="_blank"} only**. If you are using the `nodejs18.x` runtime, the AWS SDK for JavaScript v3 is already installed and you can install only the utility.
This utility supports **[AWS SDK for JavaScript v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/){target="_blank"} only**. If you are using the `nodejs18.x` runtime or newer, the AWS SDK for JavaScript v3 is already installed and you can install only the utility.


### IAM Permissions
Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Depending on the provider you want to use, install the library and the correspon
```

???+ tip
If you are using the `nodejs18.x` runtime, the AWS SDK for JavaScript v3 is already installed and you can install the utility only.
If you are using the `nodejs18.x` runtime or newer, the AWS SDK for JavaScript v3 is already installed and you can install the utility only.

### IAM Permissions

Expand Down
4 changes: 2 additions & 2 deletions examples/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/aws-lambda": "^8.10.121",
"@types/jest": "^29.5.4",
"@types/node": "20.6.1",
"aws-cdk": "^2.96.1",
"aws-cdk": "^2.107.0",
"esbuild": "^0.19.3",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
Expand All @@ -44,7 +44,7 @@
},
"dependencies": {
"@middy/core": "^3.6.2",
"aws-cdk-lib": "^2.96.1",
"aws-cdk-lib": "^2.107.0",
"constructs": "^10.2.70",
"phin": "^3.7.0",
"source-map-support": "^0.5.21"
Expand Down
4 changes: 2 additions & 2 deletions examples/cdk/src/example-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { StringParameter } from 'aws-cdk-lib/aws-ssm';
import { Construct } from 'constructs';

const commonProps: Partial<NodejsFunctionProps> = {
runtime: Runtime.NODEJS_18_X,
runtime: Runtime.NODEJS_20_X,
tracing: Tracing.ACTIVE,
timeout: Duration.seconds(30),
logRetention: RetentionDays.ONE_DAY,
Expand Down Expand Up @@ -112,7 +112,7 @@ class UuidApi extends Construct {
super(scope, id);

const uuidFn = new NodejsFunction(this, 'UuidFn', {
runtime: Runtime.NODEJS_18_X,
runtime: Runtime.NODEJS_20_X,
entry: './functions/uuid.ts',
});

Expand Down
2 changes: 1 addition & 1 deletion examples/sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Parameters:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html
Globals:
Function:
Runtime: nodejs18.x
Runtime: nodejs20.x
Architectures:
- x86_64
MemorySize: 128
Expand Down
2 changes: 1 addition & 1 deletion layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"aws-cdk": "^2.96.1",
"aws-cdk-lib": "^2.96.1",
"aws-cdk-lib": "^2.107.0",
"esbuild": "^0.19.3"
}
}
8 changes: 6 additions & 2 deletions layers/src/layer-publisher-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ export class LayerPublisherStack extends Stack {
this.lambdaLayerVersion = new LayerVersion(this, 'LambdaPowertoolsLayer', {
layerVersionName: props?.layerName,
description: `Powertools for AWS Lambda (TypeScript) version ${powertoolsPackageVersion}`,
compatibleRuntimes: [Runtime.NODEJS_16_X, Runtime.NODEJS_18_X],
compatibleRuntimes: [
Runtime.NODEJS_16_X,
Runtime.NODEJS_18_X,
Runtime.NODEJS_20_X,
],
license: 'MIT-0',
// This is needed because the following regions do not support the compatibleArchitectures property #1400
// ...(![ 'eu-south-2', 'eu-central-2', 'ap-southeast-4' ].includes(Stack.of(this).region) ? { compatibleArchitectures: [Architecture.X86_64] } : {}),
code: Code.fromAsset(resolve(__dirname), {
bundling: {
// This is here only because is required by CDK, however it is not used since the bundling is done locally
image: Runtime.NODEJS_18_X.bundlingImage,
image: Runtime.NODEJS_20_X.bundlingImage,
// We need to run a command to generate a random UUID to force the bundling to run every time
command: [`echo "${randomUUID()}"`],
local: {
Expand Down
2 changes: 1 addition & 1 deletion layers/tests/unit/layer-publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Class: LayerPublisherStack', () => {
// Assess
template.resourceCountIs('AWS::Lambda::LayerVersion', 1);
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
CompatibleRuntimes: ['nodejs16.x', 'nodejs18.x'],
CompatibleRuntimes: ['nodejs16.x', 'nodejs18.x', 'nodejs20.x'],
LicenseInfo: 'MIT-0',
/* CompatibleArchitectures: [
'x86_64',
Expand Down
Loading

0 comments on commit 5d38256

Please sign in to comment.