Skip to content

Commit

Permalink
Upgrade to be Node20 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Rooster212 committed May 16, 2024
1 parent 3232940 commit 183937b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rooster212/event-driven-dynamodb-rules-engine",
"version": "1.4.0",
"version": "1.5.0",
"description": "Events and rules engine for use with DynamoDB.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -32,7 +32,7 @@
"@aws-sdk/util-dynamodb": "3.577.0"
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@tsconfig/node20": "^20.1.4",
"@types/aws-lambda": "^8.10.137",
"@types/jest": "^26.0.8",
"@typescript-eslint/eslint-plugin": "^4.17.0",
Expand Down
22 changes: 19 additions & 3 deletions stream/dynamoDBStreamEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEventBus } from "aws-cdk-lib/aws-events";
import { Architecture, Runtime } from "aws-cdk-lib/aws-lambda";
import { Architecture, Runtime, RuntimeFamily } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction, NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
import { RetentionDays } from "aws-cdk-lib/aws-logs";

Expand All @@ -18,6 +18,18 @@ export interface DynamoDBStreamEventHandlerProps
* will be granted PutEvents permission for this event bus.
*/
targetEventBus: IEventBus;

/**
* The target runtime for the Lambda function.
* @default Runtime.NODEJS_LATEST
*/
targetRuntime?: Runtime;

/**
* The target architecture for the Lambda function.
* @default Architecture.ARM_64
*/
targetArchitecture?: Architecture;
}

export class DynamoDBStreamEventHandler extends NodejsFunction {
Expand All @@ -28,14 +40,18 @@ export class DynamoDBStreamEventHandler extends NodejsFunction {
* @param props The properties to pass. See {@link DynamoDBStreamEventHandlerProps}.
*/
constructor(scope: Construct, id: string, props: DynamoDBStreamEventHandlerProps) {
if (props.targetRuntime && props.targetRuntime?.family !== RuntimeFamily.NODEJS) {
throw new Error("The target runtime must be Node.js");
}

super(scope, id, {
bundling: {
minify: true,
sourceMap: true,
},
...props,
architecture: Architecture.ARM_64,
runtime: Runtime.NODEJS_16_X,
architecture: props.targetArchitecture ?? Architecture.ARM_64,
runtime: props.targetRuntime ?? Runtime.NODEJS_LATEST,
// I've done it like this so that it works when published as well as from TypeScript
entry: fs.existsSync(`${__dirname}/onDynamoDBStreamEvent.ts`)
? `${__dirname}/onDynamoDBStreamEvent.ts`
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"module": "Node16",
"declaration": true,
"outDir": "dist",
"strict": true,
Expand Down

0 comments on commit 183937b

Please sign in to comment.