-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
163 lines (151 loc) · 4.76 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
org: photonadmin
app: photonranch
service: photonranch-logstream
plugins:
- serverless-python-requirements
- serverless-domain-manager
custom:
# This is the 'variable' for the customDomain.basePath value, based on the stage.
stage:
prod: logs
dev: dev
pythonRequirements:
dockerizePip: non-linux
dockerFile: serverless-deploy-helpers/Dockerfile
slim: true
noDeploy:
- pytest
customDomain:
domainName: 'logs.photonranch.org'
basePath: ${self:custom.stage.${self:provider.stage}}
stage: ${self:provider.stage}
createRoute53Record: true
createRoute53IPv6Record: true
autoDomain: true # runs create_domain/delete_domain with sls deploy/remove automatically.
# Keeps the package size small
package:
patterns:
- '!node_modules/**'
- '!venv/**'
provider:
name: aws
stage: ${opt:stage, "dev"}
runtime: python3.8
region: us-east-1
environment:
LOGS_TABLE: photonranch-observatory-logs-${self:provider.stage}
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:GetItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchGetItem
- dynamodb:BatchWriteItem
- dynamodb:Scan
- dynamodb:Query
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource:
- "arn:aws:dynamodb:us-east-1:*:*"
- Effect: Allow
Action:
- sqs:SendMessage
- sqs:GetQueueUrl
Resource:
- "arn:aws:sqs:${self:provider.region}:*:*"
functions:
newLogHandler:
handler: handler.new_log_stream_handler
events:
- stream:
type: dynamodb
batchSize: 1
arn:
Fn::GetAtt:
- logsTable
- StreamArn
getRecentLogs:
handler: handler.get_recent_logs_handler
events:
- http:
path: recent-logs
method: get
cors: true
addLogEntry:
handler: handler.add_log_entry_handler
events:
- http:
path: newlog
method: post
cors: true
resources:
Resources:
logsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.environment.LOGS_TABLE}
AttributeDefinitions:
- AttributeName: site
AttributeType: S
- AttributeName: timestamp
AttributeType: N
KeySchema:
- AttributeName: site
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TimeToLiveSpecification:
AttributeName: TimeToLive
Enabled: true
StreamSpecification:
StreamViewType: NEW_IMAGE
# Configure API gateway "Gateway Responses" to work with CORS restrictions
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Access-Control-Allow-Origin'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,POST,OPTIONS'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponseDefault5XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Methods: "'GET,POST,OPTIONS'"
gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Access-Control-Allow-Origin'"
ResponseType: DEFAULT_5XX
RestApiId:
Ref: 'ApiGatewayRestApi'
GatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: EXPIRED_TOKEN
RestApiId:
Ref: 'ApiGatewayRestApi'
StatusCode: '401'
AuthFailureGatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: UNAUTHORIZED
RestApiId:
Ref: 'ApiGatewayRestApi'
StatusCode: '401'