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

+1-1
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

+2-2
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

+2-2
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

+6-6
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

+3-2
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

+2-2
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

+1-1
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

+2-2
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

+1-1
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

+2-3
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:

aws-node-sqs-worker/handler.js

+1-57
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,5 @@
1-
const { SQS } = require("aws-sdk");
2-
3-
const sqs = new SQS();
4-
5-
const producer = async (event) => {
6-
let statusCode = 200;
7-
let message;
8-
9-
if (!event.body) {
10-
return {
11-
statusCode: 400,
12-
body: JSON.stringify({
13-
message: "No body was found",
14-
}),
15-
};
16-
}
17-
18-
try {
19-
await sqs
20-
.sendMessage({
21-
QueueUrl: process.env.QUEUE_URL,
22-
MessageBody: event.body,
23-
MessageAttributes: {
24-
AttributeName: {
25-
StringValue: "Attribute Value",
26-
DataType: "String",
27-
},
28-
},
29-
})
30-
.promise();
31-
32-
message = "Message accepted!";
33-
} catch (error) {
34-
console.log(error);
35-
message = error;
36-
statusCode = 500;
37-
}
38-
39-
return {
40-
statusCode,
41-
body: JSON.stringify({
42-
message,
43-
}),
44-
};
45-
};
46-
47-
const consumer = async (event) => {
1+
exports.consumer = async (event) => {
482
for (const record of event.Records) {
49-
const messageAttributes = record.messageAttributes;
50-
console.log(
51-
"Message Attribute: ",
52-
messageAttributes.AttributeName.stringValue
53-
);
543
console.log("Message Body: ", record.body);
554
}
565
};
57-
58-
module.exports = {
59-
producer,
60-
consumer,
61-
};

aws-node-sqs-worker/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"version": "1.0.0",
44
"description": "Serverless Framework Node SQS Producer-Consumer on AWS",
55
"author": "",
6-
"license": "MIT",
7-
"devDependencies": {
8-
"serverless-lift": "^1.1.2"
9-
}
6+
"license": "MIT"
107
}

aws-node-sqs-worker/serverless.yml

+11-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
service: aws-node-sqs-worker
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

9-
constructs:
10-
jobs:
11-
type: queue
12-
worker:
13-
handler: handler.consumer
14-
159
functions:
1610
producer:
17-
handler: handler.producer
11+
handler: handler.consumer
1812
events:
19-
- httpApi:
20-
method: post
21-
path: /produce
22-
environment:
23-
QUEUE_URL: ${construct:jobs.queueUrl}
13+
- sqs: arn:aws:sqs:${aws:region}:${aws:accountId}:MyFirstQueue
14+
15+
resources:
16+
Resources:
17+
JobQueue:
18+
Type: AWS::SQS::Queue
19+
Properties:
20+
QueueName: MyFirstQueue
2421

25-
plugins:
26-
- serverless-lift

aws-node/handler.js

+1-1
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/serverless.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
service: aws-node # NOTE: update this with your service name
22

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

55

66
provider:
77
name: aws
8-
runtime: nodejs12.x
9-
lambdaHashingVersion: 20201221
8+
runtime: nodejs20.x
109

1110
functions:
1211
hello:

aws-python-flask-api/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==1.1.4
22
Werkzeug==1.0.1
3-
3+
markupsafe==2.0.1

aws-python-flask-api/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
service: aws-python-flask-api
22

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

55
custom:
66
wsgi:
77
app: app.app
88

99
provider:
1010
name: aws
11-
runtime: python3.8
11+
runtime: python3.12
1212
lambdaHashingVersion: '20201221'
1313

1414
functions:

aws-python-flask-dynamodb-api/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Example of a Python Flask API service backed by DynamoDB with traditional Serverless Framework",
55
"author": "",
66
"devDependencies": {
7-
"serverless-python-requirements": "^5.1.0",
8-
"serverless-wsgi": "^1.7.6"
7+
"serverless-python-requirements": "^6.0.1",
8+
"serverless-wsgi": "^3.0.3"
99
}
1010
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Flask==1.1.4
22
Werkzeug==1.0.1
3-
3+
markupsafe==2.0.1

aws-python-flask-dynamodb-api/serverless.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
service: aws-python-flask-dynamodb-api
22

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

55
custom:
66
tableName: 'users-table-${self:provider.stage}'
@@ -9,9 +9,8 @@ custom:
99

1010
provider:
1111
name: aws
12-
runtime: python3.8
12+
runtime: python3.12
1313
lambdaHashingVersion: '20201221'
14-
stage: dev
1514
iam:
1615
role:
1716
statements:

aws-python-http-api/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
service: aws-python-http-api
2-
frameworkVersion: '2 || 3'
2+
frameworkVersion: '4'
33

44
provider:
55
name: aws
6-
runtime: python3.8
6+
runtime: python3.12
77
lambdaHashingVersion: '20201221'
88

99
functions:

aws-python-scheduled-cron/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
service: aws-python-scheduled-cron
22

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

55

66
provider:
77
name: aws
8-
runtime: python3.8
8+
runtime: python3.12
99
lambdaHashingVersion: 20201221
1010

1111
functions:

aws-python-sqs-worker/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
service: aws-python-sqs-worker
2-
frameworkVersion: '2 || 3'
2+
frameworkVersion: '4'
33

44
provider:
55
name: aws
6-
runtime: python3.8
6+
runtime: python3.12
77
lambdaHashingVersion: '20201221'
88

99
constructs:

aws-python/serverless.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
service: aws-python # NOTE: update this with your service name
22

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

55

66
provider:
77
name: aws
8-
runtime: python3.8
8+
runtime: python3.12
99
lambdaHashingVersion: 20201221
1010

1111
functions:

0 commit comments

Comments
 (0)