-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
220 lines (204 loc) · 5.78 KB
/
template.yaml
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
todo-app
- Serverless Functions for GET/PUT/POST/DELETE
- UI Leptos WASM in an S3 bucket
Globals:
Function:
MemorySize: 128
Architectures: ["arm64"]
Handler: bootstrap
Runtime: provided.al2
Timeout: 5
Tracing: Active
LoggingConfig:
LogFormat: JSON
ApplicationLogLevel: INFO
LogGroup: TodoLogGroup
SystemLogLevel: INFO
HttpApi:
CorsConfiguration:
AllowOrigins:
- "*"
AllowMethods:
- "PUT, GET, HEAD, POST, DELETE, OPTIONS"
AllowHeaders:
- "access-control-allow-headers, access-control-allow-methods, access-control-allow-origin, access-control-allow-credentials, content-type"
MaxAge: 600
Api:
Cors:
AllowOrigin: "'*'"
AllowHeaders: "'access-control-allow-headers, access-control-allow-methods, access-control-allow-origin, access-control-allow-credentials, content-type'"
AllowMethods: "'PUT, GET, HEAD, POST, DELETE, OPTIONS'"
AllowCredentials: "'true'"
MaxAge: "'600'"
GatewayResponses:
DEFAULT_4xx:
ResponseParameters:
Headers:
Access-Control-Expose-Headers: "'WWW-Authenticate'"
Access-Control-Allow-Origin: "'*'"
DEFAULT_5xx:
ResponseParameters:
Headers:
Access-Control-Expose-Headers: "'WWW-Authenticate'"
Access-Control-Allow-Origin: "'*'"
Resources:
TodoGetListFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TodoExecutionRole.Arn
CodeUri: target/lambda/get-todos
Events:
CatchAll:
Type: Api
Properties:
Path: /
Method: get
TodoGetItemFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TodoExecutionRole.Arn
CodeUri: target/lambda/get-todo
Events:
CatchAll:
Type: Api
Properties:
Path: /{id}
Method: get
TodoAddItemFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TodoExecutionRole.Arn
CodeUri: target/lambda/add-todo
Events:
CatchAll:
Type: Api
Properties:
Path: /
Method: post
TodoEditItemFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TodoExecutionRole.Arn
CodeUri: target/lambda/edit-todo
Events:
CatchAll:
Type: Api
Properties:
Path: /
Method: put
TodoDeleteItemFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt TodoExecutionRole.Arn
CodeUri: target/lambda/delete-todo
Events:
CatchAll:
Type: Api
Properties:
Path: /{id}
Method: delete
TodoDB:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
TableName: TodoTable
TodoExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: "sts:AssumeRole"
Policies:
- PolicyName: TodoAccessPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: [
"dynamodb:DescribeTable",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:GetItem",
"dynamodb:DeleteItem",
"dynamodb:UpdateItem",
"dynamodb:PutItem"
]
Resource: "arn:aws:dynamodb:*:*:table/TodoTable"
- Effect: Allow
Action: [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource: "*"
TodoUsagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
ApiStages:
- ApiId: !Ref ServerlessRestApi
Stage: !Ref ServerlessRestApiProdStage
Description: Todo usage plan
Quota:
Limit: 1000
Period: MONTH
Throttle:
BurstLimit: 10
RateLimit: 10
UsagePlanName: TodoUsagePlan
TodoLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: TodoLogGroup
RetentionInDays: 7
S3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
# REPLACE THIS NAME BY YOUR OWN BUCKET NAME !!!
# APPLY ALSO THE NAME IN THE [MakeFile]:
# BUCKET_NAME := todo-app-xxx
BucketName: todo-app-xxx
PublicAccessBlockConfiguration:
BlockPublicAcls: false
OwnershipControls:
Rules:
- ObjectOwnership: ObjectWriter
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Id: TodoS3Policy
Version: 2012-10-17
Statement:
- Sid: PublicReadForGetBucketObjects
Effect: Allow
Principal: '*'
Action: 's3:GetObject'
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref S3Bucket
- /*
Outputs:
TodoGetListFunctionAPI:
Description: "API [get-todos] URL:"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/get-todos"
TodoBucketUrl:
Description: "S3 Website Bucket URL:"
Value: !Sub "https://${S3Bucket}.s3-website-${AWS::Region}.amazonaws.com"