-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
139 lines (132 loc) · 4.08 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
org: upstandfm
app: api
service: invites-api
plugins:
- serverless-domain-manager
custom:
customDomain:
domainName: api.upstand.fm
basePath: invites
stage: ${opt:stage, 'prod'}
createRoute53Record: false
cors:
origin: '*'
authorizer:
arn: ${secrets:AUTH0_AUTHORIZER_ARN}
resultTtlInSeconds: 60
identitySource: method.request.header.Authorization
# Note that Bearer must be capitalized
identityValidationExpression: '^Bearer [-0-9a-zA-z\.]*$'
type: token
provider:
name: aws
runtime: nodejs12.x
stage: ${opt:stage, 'prod'}
region: ${opt:region, 'eu-central-1'}
cfnRole: ${secrets:CFN_ROLE_ARN}
memorySize: 128
timeout: 3
deploymentBucket:
name: upstandfm-deployments
serverSideEncryption: AES256
environment:
# Reuse TCP connection to reduce request latency
# For more info see:
# https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md#24630
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
CORS_ALLOW_ORIGIN: ${self:custom.cors.origin}
# The ARN has the format "arn:aws:dynamodb:::table/tableName"
# Splitting on "/" gives us the name
INVITES_TABLE_NAME:
'Fn::Select':
['1', { 'Fn::Split': ['/', '${state:infra.invitesTableArn}'] }]
CREATE_WORKSPACE_INVITE_SCOPE: 'create:workspace-invite'
READ_WORKSPACE_INVITES_SCOPE: 'read:workspace-invites'
UPDATE_WORKSPACE_INVITE_STATUS_SCOPE: 'update:workspace-invite-status'
NEW_INVITE_SNS_ARN: ${state:infra.newInviteTopicArn}
DELETE_INVITE_SNS_ARN: ${state:infra.deleteInviteTopicArn}
# See: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_actions-resources-contextkeys.html
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:Query
Resource: ${state:infra.invitesTableArn}
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource: ${state:infra.invitesTableStreamArn}
- Effect: Allow
Action:
- sns:Publish
Resource: ${state:infra.newInviteTopicArn}
- Effect: Allow
Action:
- sns:Publish
Resource: ${state:infra.deleteInviteTopicArn}
package:
exclude:
- ./*
- ./**/*.spec.js
include:
- node_modules
- src
functions:
createWorkspaceInvite:
handler: src/handler.createWorkspaceInvite
description: Creates a workspace invite
events:
- http:
method: post
path: /
cors: ${self:custom.cors}
authorizer: ${self:custom.authorizer}
updateWorkspaceInviteStatus:
handler: src/handler.updateWorkspaceInviteStatus
description: Updates the status of a workspace invite
events:
- http:
method: patch
path: /status
cors: ${self:custom.cors}
authorizer: ${self:custom.authorizer}
getWorkspaceInvites:
handler: src/handler.getWorkspaceInvites
description: Gets all workspace invites
events:
- http:
method: get
path: /
cors: ${self:custom.cors}
authorizer: ${self:custom.authorizer}
processInvitesStream:
handler: src/handler.processInvitesStream
description: Publishes the change stream
events:
- stream:
type: dynamodb
arn: ${state:infra.invitesTableStreamArn}
resources:
Resources:
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'