Skip to content

Commit

Permalink
Merge pull request #776 from garethmcc/v4
Browse files Browse the repository at this point in the history
feat: add updated starter templates for SF V.4
  • Loading branch information
garethmcc authored Feb 19, 2024
2 parents bb413e5 + a5f85fb commit c3592f5
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 120 deletions.
2 changes: 1 addition & 1 deletion aws-node-express-api/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ app.use((req, res, next) => {
});
});

module.exports.handler = serverless(app);
exports.handler = serverless(app);
4 changes: 2 additions & 2 deletions aws-node-express-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"express": "^4.17.1",
"serverless-http": "^2.7.0"
"express": "^4.18.2",
"serverless-http": "^3.2.0"
}
}
4 changes: 2 additions & 2 deletions aws-node-express-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
service: aws-node-express-api
frameworkVersion: '2 || 3'
frameworkVersion: '4'

provider:
name: aws
runtime: nodejs12.x
runtime: nodejs20.x
lambdaHashingVersion: '20201221'

functions:
Expand Down
12 changes: 6 additions & 6 deletions aws-node-express-dynamodb-api/handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const AWS = require("aws-sdk");
const { DynamoDBClient, PutItemCommand, GetItemCommand } = require("@aws-sdk/client-dynamodb");
const express = require("express");
const serverless = require("serverless-http");

const app = express();

const USERS_TABLE = process.env.USERS_TABLE;
const dynamoDbClient = new AWS.DynamoDB.DocumentClient();

app.use(express.json());

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

try {
const { Item } = await dynamoDbClient.get(params).promise();
const command = new GetItemCommand(params);
const { Item } = await client.send(command);
if (Item) {
const { userId, name } = Item;
res.json({ userId, name });
Expand Down Expand Up @@ -50,7 +50,8 @@ app.post("/users", async function (req, res) {
};

try {
await dynamoDbClient.put(params).promise();
const command = new PutItemCommand(input);
await client.send(command);
res.json({ userId, name });
} catch (error) {
console.log(error);
Expand All @@ -64,5 +65,4 @@ app.use((req, res, next) => {
});
});


module.exports.handler = serverless(app);
exports.handler = serverless(app);
5 changes: 3 additions & 2 deletions aws-node-express-dynamodb-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"express": "^4.17.1",
"serverless-http": "^2.7.0"
"express": "^4.18.2",
"serverless-http": "^3.2.0",
"@aws-sdk/client-dynamodb": "^3.515.0"
}
}
4 changes: 2 additions & 2 deletions aws-node-express-dynamodb-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
service: aws-node-express-dynamodb-api
frameworkVersion: '2 || 3'
frameworkVersion: '4'

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

provider:
name: aws
runtime: nodejs12.x
runtime: nodejs20.x
lambdaHashingVersion: '20201221'
iam:
role:
Expand Down
2 changes: 1 addition & 1 deletion aws-node-http-api/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

module.exports.hello = async (event) => {
exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify(
Expand Down
4 changes: 2 additions & 2 deletions aws-node-http-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
service: serverless-http-api
frameworkVersion: '2 || 3'
frameworkVersion: '4'

provider:
name: aws
runtime: nodejs12.x
runtime: nodejs20.x
lambdaHashingVersion: '20201221'

functions:
Expand Down
2 changes: 1 addition & 1 deletion aws-node-scheduled-cron/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports.run = async (event, context) => {
exports.run = async (event, context) => {
const time = new Date();
console.log(`Your cron function "${context.functionName}" ran at ${time}`);
};
5 changes: 2 additions & 3 deletions aws-node-scheduled-cron/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
service: aws-node-scheduled-cron

frameworkVersion: '2 || 3'

frameworkVersion: '4'

provider:
name: aws
runtime: nodejs12.x
runtime: nodejs20.x
lambdaHashingVersion: 20201221

functions:
Expand Down
58 changes: 1 addition & 57 deletions aws-node-sqs-worker/handler.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,5 @@
const { SQS } = require("aws-sdk");

const sqs = new SQS();

const producer = async (event) => {
let statusCode = 200;
let message;

if (!event.body) {
return {
statusCode: 400,
body: JSON.stringify({
message: "No body was found",
}),
};
}

try {
await sqs
.sendMessage({
QueueUrl: process.env.QUEUE_URL,
MessageBody: event.body,
MessageAttributes: {
AttributeName: {
StringValue: "Attribute Value",
DataType: "String",
},
},
})
.promise();

message = "Message accepted!";
} catch (error) {
console.log(error);
message = error;
statusCode = 500;
}

return {
statusCode,
body: JSON.stringify({
message,
}),
};
};

const consumer = async (event) => {
exports.consumer = async (event) => {
for (const record of event.Records) {
const messageAttributes = record.messageAttributes;
console.log(
"Message Attribute: ",
messageAttributes.AttributeName.stringValue
);
console.log("Message Body: ", record.body);
}
};

module.exports = {
producer,
consumer,
};
5 changes: 1 addition & 4 deletions aws-node-sqs-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
"version": "1.0.0",
"description": "Serverless Framework Node SQS Producer-Consumer on AWS",
"author": "",
"license": "MIT",
"devDependencies": {
"serverless-lift": "^1.1.2"
}
"license": "MIT"
}
27 changes: 11 additions & 16 deletions aws-node-sqs-worker/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
service: aws-node-sqs-worker
frameworkVersion: '2 || 3'
frameworkVersion: '4'

provider:
name: aws
runtime: nodejs12.x
runtime: nodejs20.x
lambdaHashingVersion: '20201221'

constructs:
jobs:
type: queue
worker:
handler: handler.consumer

functions:
producer:
handler: handler.producer
handler: handler.consumer
events:
- httpApi:
method: post
path: /produce
environment:
QUEUE_URL: ${construct:jobs.queueUrl}
- sqs: arn:aws:sqs:${aws:region}:${aws:accountId}:MyFirstQueue

resources:
Resources:
JobQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: MyFirstQueue

plugins:
- serverless-lift
2 changes: 1 addition & 1 deletion aws-node/handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports.hello = async (event) => {
exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify(
Expand Down
5 changes: 2 additions & 3 deletions aws-node/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
service: aws-node # NOTE: update this with your service name

frameworkVersion: '2 || 3'
frameworkVersion: '4'


provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
runtime: nodejs20.x

functions:
hello:
Expand Down
2 changes: 1 addition & 1 deletion aws-python-flask-api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==1.1.4
Werkzeug==1.0.1

markupsafe==2.0.1
4 changes: 2 additions & 2 deletions aws-python-flask-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
service: aws-python-flask-api

frameworkVersion: '2 || 3'
frameworkVersion: '4'

custom:
wsgi:
app: app.app

provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: '20201221'

functions:
Expand Down
4 changes: 2 additions & 2 deletions aws-python-flask-dynamodb-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Example of a Python Flask API service backed by DynamoDB with traditional Serverless Framework",
"author": "",
"devDependencies": {
"serverless-python-requirements": "^5.1.0",
"serverless-wsgi": "^1.7.6"
"serverless-python-requirements": "^6.0.1",
"serverless-wsgi": "^3.0.3"
}
}
2 changes: 1 addition & 1 deletion aws-python-flask-dynamodb-api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==1.1.4
Werkzeug==1.0.1

markupsafe==2.0.1
5 changes: 2 additions & 3 deletions aws-python-flask-dynamodb-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
service: aws-python-flask-dynamodb-api

frameworkVersion: '2 || 3'
frameworkVersion: '4'

custom:
tableName: 'users-table-${self:provider.stage}'
Expand All @@ -9,9 +9,8 @@ custom:

provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: '20201221'
stage: dev
iam:
role:
statements:
Expand Down
4 changes: 2 additions & 2 deletions aws-python-http-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
service: aws-python-http-api
frameworkVersion: '2 || 3'
frameworkVersion: '4'

provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: '20201221'

functions:
Expand Down
4 changes: 2 additions & 2 deletions aws-python-scheduled-cron/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
service: aws-python-scheduled-cron

frameworkVersion: '2 || 3'
frameworkVersion: '4'


provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: 20201221

functions:
Expand Down
4 changes: 2 additions & 2 deletions aws-python-sqs-worker/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
service: aws-python-sqs-worker
frameworkVersion: '2 || 3'
frameworkVersion: '4'

provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: '20201221'

constructs:
Expand Down
4 changes: 2 additions & 2 deletions aws-python/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
service: aws-python # NOTE: update this with your service name

frameworkVersion: '2 || 3'
frameworkVersion: '4'


provider:
name: aws
runtime: python3.8
runtime: python3.12
lambdaHashingVersion: 20201221

functions:
Expand Down

0 comments on commit c3592f5

Please sign in to comment.