-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
97 lines (88 loc) · 2.67 KB
/
serverless.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
service: tasks-api-serverless
frameworkVersion: "3"
package:
individually: true
provider:
name: aws
runtime: nodejs16.x
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'ap-south-1'}
memorySize: 128
logRetentionInDays: 1
environment:
TASKS_TABLE_NAME: !Ref TasksTable
REGION: ${self:provider.region}
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
httpApi:
authorizers:
tokenAuth:
type: request
identitySource:
- $request.header.Authorization
functionName: tokenAuthorizer
jwtCognitoAuthorizer:
type: jwt
identitySource: $request.header.Authorization
audience: ${self:custom.COGNITO_USER_POOL_CLIENT}
issuerUrl: !Join ["", [ "https://cognito-idp.", "${opt:region, self:provider.region}", ".amazonaws.com/", "${self:custom.COGNITO_USER_POOL_ID}" ] ]
# issuerUrl:
# Fn::Join:
# - ""
# - - "https://cognito-idp."
# - "${opt:region, self:provider.region}"
# - ".amazonaws.com/"
# - ${self:custom.COGNITO_USER_POOL_ID}
functions:
tokenAuthorizer:
handler: src/authorizers/tokenAuthorizer.handler
createNote:
handler: src/handlers/createTask.handler
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:PutItem
Resource: !GetAtt TasksTable.Arn
events:
- httpApi:
path: /tasks
method: post
authorizer: tokenAuth
updateNote:
handler: src/handlers/updateTask.handler
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:UpdateItem
Resource: !GetAtt TasksTable.Arn
events:
- httpApi:
path: /tasks/{id}
method: put
authorizer: tokenAuth
getNotes:
handler: src/handlers/getTasks.handler
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:Scan
Resource: !GetAtt TasksTable.Arn
events:
- httpApi:
path: /tasks
method: get
authorizer: jwtCognitoAuthorizer
plugins:
- serverless-iam-roles-per-function
- serverless-plugin-include-dependencies
resources:
Resources:
TasksTable: ${file(resources/TaskTable.yml):TasksTable}
CognitoUserPool: ${file(resources/Cognito.yml):CognitoUserPool}
CognitoUserPoolClient: ${file(resources/Cognito.yml):CognitoUserPoolClient}
CognitoUserPoolDomain: ${file(resources/Cognito.yml):CognitoUserPoolDomain}
custom:
COGNITO_USER_POOL_ID: !Ref CognitoUserPool
COGNITO_USER_POOL_CLIENT: !Ref CognitoUserPoolClient