Skip to content

Commit 9ea7045

Browse files
authored
feat: Updated node v3 templates to node v18 (serverless#740)
1 parent b80e2c3 commit 9ea7045

File tree

16 files changed

+285
-294
lines changed

16 files changed

+285
-294
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@
22
33
Thanks for submitting a PR! We're excited to see what you've got for us!
44
5-
Make sure to lint your code to match the rest of the repo.
6-
7-
Run `npm run lint` to lint
8-
95
-->

aws-node-express-api/handler.js renamed to aws-node-express-api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ app.get("/", (req, res, next) => {
88
});
99
});
1010

11-
app.get("/hello", (req, res, next) => {
11+
app.get("/path", (req, res, next) => {
1212
return res.status(200).json({
1313
message: "Hello from path!",
1414
});

aws-node-express-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"dependencies": {
6-
"express": "^4.17.1",
7-
"serverless-http": "^2.7.0"
6+
"express": "^4.18.2",
7+
"serverless-http": "^3.1.1"
88
}
99
}

aws-node-express-api/serverless.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ frameworkVersion: '3'
33

44
provider:
55
name: aws
6-
runtime: nodejs14.x
6+
runtime: nodejs18.x
77

88
functions:
99
api:
10-
handler: handler.handler
10+
handler: index.handler
1111
events:
1212
- httpApi: '*'

aws-node-express-dynamodb-api/handler.js renamed to aws-node-express-dynamodb-api/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
const AWS = require("aws-sdk");
1+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
2+
const {
3+
DynamoDBDocumentClient,
4+
GetCommand,
5+
PutCommand,
6+
} = require("@aws-sdk/lib-dynamodb");
27
const express = require("express");
38
const serverless = require("serverless-http");
49

10+
511
const app = express();
612

713
const USERS_TABLE = process.env.USERS_TABLE;
8-
const dynamoDbClient = new AWS.DynamoDB.DocumentClient();
14+
const client = new DynamoDBClient();
15+
const dynamoDbClient = DynamoDBDocumentClient.from(client);
916

1017
app.use(express.json());
1118

@@ -18,7 +25,7 @@ app.get("/users/:userId", async function (req, res) {
1825
};
1926

2027
try {
21-
const { Item } = await dynamoDbClient.get(params).promise();
28+
const { Item } = await dynamoDbClient.send(new GetCommand(params));
2229
if (Item) {
2330
const { userId, name } = Item;
2431
res.json({ userId, name });
@@ -50,7 +57,7 @@ app.post("/users", async function (req, res) {
5057
};
5158

5259
try {
53-
await dynamoDbClient.put(params).promise();
60+
await dynamoDbClient.send(new PutCommand(params));
5461
res.json({ userId, name });
5562
} catch (error) {
5663
console.log(error);

aws-node-express-dynamodb-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"dependencies": {
6-
"express": "^4.17.1",
7-
"serverless-http": "^2.7.0"
6+
"express": "^4.18.2",
7+
"serverless-http": "^3.1.1"
88
}
99
}

aws-node-express-dynamodb-api/serverless.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ custom:
66

77
provider:
88
name: aws
9-
runtime: nodejs14.x
9+
runtime: nodejs18.x
1010
iam:
1111
role:
1212
statements:
@@ -25,7 +25,7 @@ provider:
2525

2626
functions:
2727
api:
28-
handler: handler.handler
28+
handler: index.handler
2929
events:
3030
- httpApi: '*'
3131

aws-node-http-api/handler.js renamed to aws-node-http-api/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"use strict";
2-
3-
module.exports.hello = async (event) => {
1+
module.exports.handler = async (event) => {
42
return {
53
statusCode: 200,
64
body: JSON.stringify(

aws-node-http-api/serverless.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ frameworkVersion: '3'
33

44
provider:
55
name: aws
6-
runtime: nodejs14.x
6+
runtime: nodejs18.x
77

88
functions:
9-
hello:
10-
handler: handler.hello
9+
api:
10+
handler: index.handler
1111
events:
1212
- httpApi:
1313
path: /

aws-node-scheduled-cron/handler.js renamed to aws-node-scheduled-cron/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
module.exports.run = async (event, context) => {
42
const time = new Date();
53
console.log(`Your cron function "${context.functionName}" ran at ${time}`);

0 commit comments

Comments
 (0)