Skip to content

Commit a5f85fb

Browse files
author
Gareth Mc Cumskey
committed
feat: add updated starter templates for SF V.4
1 parent bb413e5 commit a5f85fb

File tree

24 files changed

+54
-120
lines changed

24 files changed

+54
-120
lines changed

aws-node-express-api/handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ app.use((req, res, next) => {
2020
});
2121
});
2222

23-
module.exports.handler = serverless(app);
23+
exports.handler = serverless(app);

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.2.0"
88
}
99
}

aws-node-express-api/serverless.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
service: aws-node-express-api
2-
frameworkVersion: '2 || 3'
2+
frameworkVersion: '4'
33

44
provider:
55
name: aws
6-
runtime: nodejs12.x
6+
runtime: nodejs20.x
77
lambdaHashingVersion: '20201221'
88

99
functions:

aws-node-express-dynamodb-api/handler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
const AWS = require("aws-sdk");
1+
const { DynamoDBClient, PutItemCommand, GetItemCommand } = require("@aws-sdk/client-dynamodb");
22
const express = require("express");
33
const serverless = require("serverless-http");
44

55
const app = express();
66

77
const USERS_TABLE = process.env.USERS_TABLE;
8-
const dynamoDbClient = new AWS.DynamoDB.DocumentClient();
98

109
app.use(express.json());
1110

@@ -18,7 +17,8 @@ app.get("/users/:userId", async function (req, res) {
1817
};
1918

2019
try {
21-
const { Item } = await dynamoDbClient.get(params).promise();
20+
const command = new GetItemCommand(params);
21+
const { Item } = await client.send(command);
2222
if (Item) {
2323
const { userId, name } = Item;
2424
res.json({ userId, name });
@@ -50,7 +50,8 @@ app.post("/users", async function (req, res) {
5050
};
5151

5252
try {
53-
await dynamoDbClient.put(params).promise();
53+
const command = new PutItemCommand(input);
54+
await client.send(command);
5455
res.json({ userId, name });
5556
} catch (error) {
5657
console.log(error);
@@ -64,5 +65,4 @@ app.use((req, res, next) => {
6465
});
6566
});
6667

67-
68-
module.exports.handler = serverless(app);
68+
exports.handler = serverless(app);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
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.2.0",
8+
"@aws-sdk/client-dynamodb": "^3.515.0"
89
}
910
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
service: aws-node-express-dynamodb-api
2-
frameworkVersion: '2 || 3'
2+
frameworkVersion: '4'
33

44
custom:
55
tableName: 'users-table-${sls:stage}'
66

77
provider:
88
name: aws
9-
runtime: nodejs12.x
9+
runtime: nodejs20.x
1010
lambdaHashingVersion: '20201221'
1111
iam:
1212
role:

aws-node-http-api/handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
module.exports.hello = async (event) => {
3+
exports.hello = async (event) => {
44
return {
55
statusCode: 200,
66
body: JSON.stringify(

aws-node-http-api/serverless.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
service: serverless-http-api
2-
frameworkVersion: '2 || 3'
2+
frameworkVersion: '4'
33

44
provider:
55
name: aws
6-
runtime: nodejs12.x
6+
runtime: nodejs20.x
77
lambdaHashingVersion: '20201221'
88

99
functions:

aws-node-scheduled-cron/handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
module.exports.run = async (event, context) => {
3+
exports.run = async (event, context) => {
44
const time = new Date();
55
console.log(`Your cron function "${context.functionName}" ran at ${time}`);
66
};

aws-node-scheduled-cron/serverless.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
service: aws-node-scheduled-cron
22

3-
frameworkVersion: '2 || 3'
4-
3+
frameworkVersion: '4'
54

65
provider:
76
name: aws
8-
runtime: nodejs12.x
7+
runtime: nodejs20.x
98
lambdaHashingVersion: 20201221
109

1110
functions:

0 commit comments

Comments
 (0)