Skip to content

Commit

Permalink
feat: add Node.js 18 Lambda runtime (#2289)
Browse files Browse the repository at this point in the history
Updates to LambdaRuntime to deprecate NODEJS_10_X and inclusion of NODEJS_18_X

https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

All tests pass and tested with project using NODEJS_18_X.

Inclusion of Go in CONTRIBUTING guidelines as build failed before installing Go.  

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
Court Schuett authored Dec 12, 2022
1 parent 3bac7d5 commit 133b10a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
34 changes: 18 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ The following tools need to be installed to develop on projen locally.
- [Node]
- [Yarn]
- [Maven]
- [Go]

[Node]: https://nodejs.org/en/download/
[Yarn]: https://yarnpkg.com/en/docs/install
[Maven]: https://maven.apache.org/install
[node]: https://nodejs.org/en/download/
[yarn]: https://yarnpkg.com/en/docs/install
[maven]: https://maven.apache.org/install
[go]: https://go.dev/doc/install

## Getting Started

Expand Down Expand Up @@ -99,7 +101,7 @@ $ yarn link projen
$ pj
```

From now on, running `pj` in this session will use the local development version of
From now on, running `pj` in this session will use the local development version of
projen instead of the latest one from npm.

```console
Expand All @@ -115,20 +117,20 @@ npm utility.

## Making a pull request

* Commit title and message (and PR title and description) must adhere to [conventionalcommits](https://www.conventionalcommits.org).
* The title must begin with `feat(module): title`, `fix(module): title`,
`refactor(module): title` or `chore(module): title`, where the module refers
to the projects or components that the change centers on.
The module can be omitted, so "feat: title" is okay as well.
* Title should be lowercase.
* No period at the end of the title.
* Commit message should describe _motivation_. Think about your code reviewers and what information they need in
- Commit title and message (and PR title and description) must adhere to [conventionalcommits](https://www.conventionalcommits.org).
- The title must begin with `feat(module): title`, `fix(module): title`,
`refactor(module): title` or `chore(module): title`, where the module refers
to the projects or components that the change centers on.
The module can be omitted, so "feat: title" is okay as well.
- Title should be lowercase.
- No period at the end of the title.
- Commit message should describe _motivation_. Think about your code reviewers and what information they need in
order to understand what you did. If it's a big commit (hopefully not), try to provide some good entry points so
it will be easier to follow.
* Commit message should indicate which issues are fixed: `fixes #<issue>` or `closes #<issue>`.
* Shout out to collaborators.
* If not obvious (i.e. from unit tests), describe how you verified that your change works.
* If this commit includes breaking changes, they must be listed at the end in the following format (notice how multiple breaking changes should be formatted):
- Commit message should indicate which issues are fixed: `fixes #<issue>` or `closes #<issue>`.
- Shout out to collaborators.
- If not obvious (i.e. from unit tests), describe how you verified that your change works.
- If this commit includes breaking changes, they must be listed at the end in the following format (notice how multiple breaking changes should be formatted):

```
BREAKING CHANGE: Description of what broke and how to achieve this behavior now
Expand Down
3 changes: 2 additions & 1 deletion docs/api/API.md

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

1 change: 1 addition & 0 deletions src/awscdk/lambda-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class LambdaExtension extends Component {
}

const compatibleRuntimes = options.compatibleRuntimes ?? [
LambdaRuntime.NODEJS_18_X,
LambdaRuntime.NODEJS_16_X,
LambdaRuntime.NODEJS_14_X,
LambdaRuntime.NODEJS_12_X,
Expand Down
9 changes: 9 additions & 0 deletions src/awscdk/lambda-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export class LambdaFunction extends Component {
export class LambdaRuntime {
/**
* Node.js 10.x
* @deprecated NodeJS10 has been deprecated
*/
public static readonly NODEJS_10_X = new LambdaRuntime(
"nodejs10.x",
Expand Down Expand Up @@ -319,6 +320,14 @@ export class LambdaRuntime {
"node16"
);

/**
* Node.js 18.x
*/
public static readonly NODEJS_18_X = new LambdaRuntime(
"nodejs18.x",
"node18"
);

public readonly esbuildPlatform = "node";

public constructor(
Expand Down
1 change: 1 addition & 0 deletions test/awscdk/__snapshots__/lambda-extension.test.ts.snap

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

4 changes: 2 additions & 2 deletions test/awscdk/awscdk-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("lambda functions", () => {
cdkVersion: "1.100.0",
libdir: "liblib",
lambdaOptions: {
runtime: LambdaRuntime.NODEJS_10_X,
runtime: LambdaRuntime.NODEJS_18_X,
bundlingOptions: {
externals: ["foo", "bar"],
},
Expand All @@ -61,7 +61,7 @@ describe("lambda functions", () => {
snapshot[".projen/tasks.json"].tasks["bundle:my.lambda"].steps
).toStrictEqual([
{
exec: 'esbuild --bundle src/my.lambda.ts --target="node10" --platform="node" --outfile="assets/my.lambda/index.js" --tsconfig="tsconfig.dev.json" --external:foo --external:bar',
exec: 'esbuild --bundle src/my.lambda.ts --target="node18" --platform="node" --outfile="assets/my.lambda/index.js" --tsconfig="tsconfig.dev.json" --external:foo --external:bar',
},
]);
});
Expand Down
4 changes: 2 additions & 2 deletions test/awscdk/awscdk-construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe("lambda functions", () => {
assetsDir: "resources",
},
lambdaOptions: {
runtime: awscdk.LambdaRuntime.NODEJS_10_X,
runtime: awscdk.LambdaRuntime.NODEJS_18_X,
bundlingOptions: {
externals: ["foo", "bar"],
sourcemap: true,
Expand All @@ -190,7 +190,7 @@ describe("lambda functions", () => {
snapshot[".projen/tasks.json"].tasks["bundle:my.lambda"].steps
).toStrictEqual([
{
exec: 'esbuild --bundle src/my.lambda.ts --target="node10" --platform="node" --outfile="resources/my.lambda/index.js" --tsconfig="tsconfig.dev.json" --external:foo --external:bar --sourcemap',
exec: 'esbuild --bundle src/my.lambda.ts --target="node18" --platform="node" --outfile="resources/my.lambda/index.js" --tsconfig="tsconfig.dev.json" --external:foo --external:bar --sourcemap',
},
]);
});
Expand Down
14 changes: 14 additions & 0 deletions test/awscdk/lambda-extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ test("simplest LambdaExtension cdk v2", () => {
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs14.x', lambda.RuntimeFamily.NODEJS)"
);
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs16.x', lambda.RuntimeFamily.NODEJS)"
);
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs18.x', lambda.RuntimeFamily.NODEJS)"
);
expect(generatedSource).toMatchSnapshot();
});

Expand Down Expand Up @@ -93,6 +99,8 @@ test("changing compatible runtimes", () => {
cdkDeps: cdkDepsForProject(project),
entrypoint: "src/example.lambda-extension.ts",
compatibleRuntimes: [
LambdaRuntime.NODEJS_18_X,
LambdaRuntime.NODEJS_16_X,
LambdaRuntime.NODEJS_14_X,
LambdaRuntime.NODEJS_12_X,
LambdaRuntime.NODEJS_10_X,
Expand Down Expand Up @@ -121,6 +129,12 @@ test("changing compatible runtimes", () => {
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs14.x', lambda.RuntimeFamily.NODEJS)"
);
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs16.x', lambda.RuntimeFamily.NODEJS)"
);
expect(generatedSource).toContain(
"new lambda.Runtime('nodejs18.x', lambda.RuntimeFamily.NODEJS)"
);
});

test("bundler options", () => {
Expand Down

0 comments on commit 133b10a

Please sign in to comment.