Skip to content

Commit

Permalink
upgrade serverless framework to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
kudoh committed May 12, 2022
1 parent 6aaeec0 commit 6e6c7bd
Show file tree
Hide file tree
Showing 11 changed files with 5,496 additions and 16,192 deletions.
4 changes: 0 additions & 4 deletions .env.dev

This file was deleted.

Empty file removed .env.prod
Empty file.
2 changes: 1 addition & 1 deletion check/http-client.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"baseUrl": "localhost:3000/dev"
},
"prod": {
"baseUrl": "pvz4xc9vb6.execute-api.ap-northeast-1.amazonaws.com/prod"
"baseUrl": "https://ng8kpyntcd.execute-api.ap-northeast-1.amazonaws.com/prod"
}
}
16 changes: 8 additions & 8 deletions check/rest-api.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Content-Type: application/json
}

> {%
client.test("status=200", function () {
client.assert(response.status === 200, "status code error")
client.test("status=201", function () {
client.assert(response.status === 201, "status code error")
client.global.set("listId", response.body.data.listId)
})
%}
Expand Down Expand Up @@ -44,8 +44,8 @@ POST {{baseUrl}}/task
}

> {%
client.test("status=200", function () {
client.assert(response.status === 200, "status code error")
client.test("status=201", function () {
client.assert(response.status === 201, "status code error")
client.global.set("taskId", response.body.data.taskId)
})
%}
Expand Down Expand Up @@ -84,17 +84,17 @@ DELETE {{baseUrl}}/task?listId={{listId}}&taskId={{taskId}}
}

> {%
client.test("status=200", function () {
client.assert(response.status === 200, "status code error")
client.test("status=204", function () {
client.assert(response.status === 204, "status code error")
})
%}

### test DELETE /list
DELETE {{baseUrl}}/list?listId={{listId}}

> {%
client.test("status=200", function () {
client.assert(response.status === 200, "status code error")
client.test("status=204", function () {
client.assert(response.status === 204, "status code error")
})
%}

21,419 changes: 5,370 additions & 16,049 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@
"validate.js": "^0.13.1"
},
"devDependencies": {
"@serverless/typescript": "^3.17.0",
"@types/aws-lambda": "^8.10.17",
"@types/node": "^10.12.18",
"@types/serverless": "^1.78.20",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"esbuild": "^0.14.39",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"serverless": "^2.28.0",
"serverless": "^3.15.2",
"serverless-api-gateway-throttling": "^1.1.0",
"serverless-bundle": "^3.2.1",
"serverless-dotenv-plugin": "^3.7.2",
"serverless-dynamodb-local": "^0.2.39",
"serverless-esbuild": "^1.27.0",
"serverless-offline": "^6.8.0",
"serverless-plugin-aws-alerts": "^1.7.1",
"serverless-plugin-subscription-filter": "^1.0.7",
"source-map-support": "^0.5.21",
"ts-node": "^10.7.0",
"typescript": "^4.1.5"
},
"author": "noboru-kudo",
Expand Down
7 changes: 3 additions & 4 deletions resources/cloudwatch-alarms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { CloudFormationResource } from "serverless/plugins/aws/provider/awsProvider";

export default {
// AlertTopic: {
// Type: "AWS::SNS::Topic",
Expand All @@ -15,6 +13,7 @@ export default {
// },
// } as CloudFormationResource,
ThrottlingFilter: {
DependsOn: ["ApiGatewayLogGroup"],
Type: "AWS::Logs::MetricFilter",
DeletionPolicy: "Delete",
Properties: {
Expand All @@ -29,7 +28,7 @@ export default {
},
],
},
} as CloudFormationResource,
},
ThrottlingAlarm: {
Type: "AWS::CloudWatch::Alarm",
DeletionPolicy: "Delete",
Expand All @@ -47,5 +46,5 @@ export default {
Period: 60,
Statistic: "Sum",
},
} as CloudFormationResource,
} ,
};
6 changes: 2 additions & 4 deletions resources/dynamodb-tables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { CloudFormationResource } from "serverless/plugins/aws/provider/awsProvider";

export default {
ListTable: {
Type: "AWS::DynamoDB::Table",
Expand All @@ -13,7 +11,7 @@ export default {
WriteCapacityUnits: "${self:custom.tableThroughput}",
},
},
} as CloudFormationResource,
},
TasksTable: {
Type: "AWS::DynamoDB::Table",
DeletionPolicy: "Delete",
Expand Down Expand Up @@ -46,5 +44,5 @@ export default {
},
],
},
} as CloudFormationResource,
},
};
8 changes: 0 additions & 8 deletions resources/functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// import { AwsFunctionHandler } from "serverless/plugins/aws/provider/awsProvider";
//
// declare module "serverless" {
// export interface Event {
// subscriptionFilter: any;
// }
// }

export default {
createList: {
handler: "handler.createList",
Expand Down
176 changes: 89 additions & 87 deletions serverless.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,15 @@
import type { Serverless } from "serverless/aws";
import type { AWS } from "@serverless/typescript";
import dynamoDbTables from "./resources/dynamodb-tables";
import cloudwatchAlarms from "./resources/cloudwatch-alarms";
import functions from "./resources/functions";

const serverlessConfiguration: Serverless = {
const serverlessConfiguration: AWS = {
service: "todo-list",
frameworkVersion: "2",
custom: {
region: "${opt:region, self:provider.region}",
stage: "${opt:stage, self:provider.stage}",
prod: {
GW_ID: {
Ref: "ApiGatewayRestApi",
},
},
dev: {
GW_ID: "http://localhost:3000/",
},
notificationMailAddress: "${opt:mail, 'noboru-kudo@mamezou.com'}",
listTable: "${self:service}-list-table-${opt:stage, self:provider.stage}",
tasksTable: "${self:service}-tasks-table-${opt:stage, self:provider.stage}",
tableThroughputs: {
prod: 5,
default: 1,
},
tableThroughput:
"${self:custom.tableThroughputs.${self:custom.stage}, self:custom.tableThroughputs.default}",
dynamodb: {
stages: ["dev"],
start: {
port: 8008,
inMemory: true,
heapInitial: "200m",
heapMax: "1g",
migrate: true,
seed: true,
convertEmptyValues: true,
},
},
"serverless-offline": {
httpPort: 3000,
babelOptions: {
presets: ["env"],
},
},
// bundle: {
// disableForkTsChecker: true,
// },
apiGatewayThrottling: {
maxRequestsPerSecond: 10,
maxConcurrentRequests: 5,
},
alerts: {
stages: ["prod"],
topics: {
alarm: {
topic: "${self:service}-${self:custom.stage}-alerts-alarm",
notifications: [
{
protocol: "email",
endpoint: "${self:custom.notificationMailAddress}",
},
],
},
},
alarms: ["functionErrors", "functionThrottles"],
},
},
frameworkVersion: "3",
plugins: [
"serverless-bundle",
"serverless-esbuild",
"serverless-dynamodb-local",
"serverless-offline",
"serverless-dotenv-plugin",
"serverless-api-gateway-throttling",
"serverless-plugin-subscription-filter",
"serverless-plugin-aws-alerts",
Expand All @@ -81,7 +19,7 @@ const serverlessConfiguration: Serverless = {
},
provider: {
name: "aws",
runtime: "nodejs12.x",
runtime: "nodejs14.x",
stage: "dev",
region: "ap-northeast-1",
logs: {
Expand Down Expand Up @@ -118,30 +56,94 @@ const serverlessConfiguration: Serverless = {
LIST_TABLE: "${self:custom.listTable}",
TASKS_TABLE: "${self:custom.tasksTable}",
},
iamRoleStatements: [
{
Effect: "Allow",
Action: [
"dynamodb:DescribeTable",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
],
Resource: [
{ "Fn::GetAtt": ["ListTable", "Arn"] },
{ "Fn::GetAtt": ["TasksTable", "Arn"] },
iam: {
role: {
statements: [
{
"Fn::Join": [
"/",
[{ "Fn::GetAtt": ["TasksTable", "Arn"] }, "index", "list_index"],
Effect: "Allow",
Action: [
"dynamodb:DescribeTable",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
],
Resource: [
{ "Fn::GetAtt": ["ListTable", "Arn"] },
{ "Fn::GetAtt": ["TasksTable", "Arn"] },
{
"Fn::Join": [
"/",
[{ "Fn::GetAtt": ["TasksTable", "Arn"] }, "index", "list_index"],
],
},
],
},
],
]
}
},
},
custom: {
region: "${opt:region, self:provider.region}",
stage: "${opt:stage, self:provider.stage}",
notificationMailAddress: "${opt:mail, 'noboru-kudo@mamezou.com'}",
listTable: "${self:service}-list-table-${opt:stage, self:provider.stage}",
tasksTable: "${self:service}-tasks-table-${opt:stage, self:provider.stage}",
tableThroughputs: {
prod: 5,
default: 1,
},
tableThroughput:
"${self:custom.tableThroughputs.${self:custom.stage}, self:custom.tableThroughputs.default}",
dynamodb: {
stages: ["dev"],
start: {
port: 8008,
inMemory: true,
heapInitial: "200m",
heapMax: "1g",
migrate: true,
seed: true,
convertEmptyValues: true,
},
},
esbuild: {
bundle: true,
minify: true,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node14',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
},
"serverless-offline": {
httpPort: 3000,
babelOptions: {
presets: ["env"],
},
},
apiGatewayThrottling: {
maxRequestsPerSecond: 10,
maxConcurrentRequests: 5,
},
alerts: {
stages: ["prod"],
topics: {
alarm: {
topic: "${self:service}-${self:custom.stage}-alerts-alarm",
notifications: [
{
protocol: "email",
endpoint: "${self:custom.notificationMailAddress}",
},
],
},
},
],
alarms: ["functionErrors", "functionThrottles"],
},
},
functions,
resources: {
Expand Down
Loading

0 comments on commit 6e6c7bd

Please sign in to comment.