-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
229 lines (209 loc) · 6.28 KB
/
Copy pathtemplate.yaml
File metadata and controls
229 lines (209 loc) · 6.28 KB
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
221
222
223
224
225
226
227
228
229
Transform: AWS::Serverless-2016-10-31
Parameters:
Product:
Description: Product name
Type: String
Environment:
Description: An environment name that will be prefixed to resource names
Type: String
Default: development
SwaggerS3Path:
Description: An S3 path to swagger.yaml that will be embeded into the API gateway definition
Type: String
Globals:
Function:
Runtime: ruby2.5
Timeout: 10
Environment:
Variables:
S3_BUCKET: !Ref S3Bucket
DOCUMENTS_TABLE: !Ref DocumentsDBTable
STATE_CHANGED_TOPIC: !Ref StateChangedSNSTopic
Layers:
- !Ref SharedLayer
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Environment
DefinitionBody:
Fn::Transform:
Name: 'AWS::Include'
Parameters:
Location: !Ref SwaggerS3Path
CreateDocumentFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 'app/create_document/'
Handler: lambda.CreateDocument.handler
Layers:
- !Ref CreateDocumentGemsLayer
Policies:
- S3CrudPolicy:
BucketName: !Ref S3Bucket
- DynamoDBCrudPolicy:
TableName: !Ref DocumentsDBTable
Events:
PostDocumentApi:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /documents
Method: POST
CreateDocumentGemsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: create-document-gems
ContentUri: layers/create_document/
CompatibleRuntimes:
- ruby2.5
RetentionPolicy: Delete
ListenDocumentStreamFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 'app/listen_document_stream/'
Handler: lambda.ListenDocumentStream.handler
Environment:
Variables:
DOCUMENT_CREATED_TOPIC: !Ref DocumentCreatedSNSTopic
Events:
Stream:
Type: DynamoDB
Properties:
Stream: !GetAtt DocumentsDBTable.StreamArn
BatchSize: 10
# MaximumBatchingWindowInSeconds: 10
StartingPosition: LATEST
Policies:
- S3ReadPolicy:
BucketName: !Ref S3Bucket
- DynamoDBReadPolicy:
TableName: !Ref DocumentsDBTable
- SNSPublishMessagePolicy:
TopicName: !GetAtt DocumentCreatedSNSTopic.TopicName
- SNSPublishMessagePolicy:
TopicName: !GetAtt StateChangedSNSTopic.TopicName
DispatchrFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 'app/dispatchr/'
Handler: lambda.Dispatchr.handler
Environment:
Variables:
RENDER_TEMPLATE_FUNCTION: !Ref RenderTemplateFunction
GENERATE_PDF_FUNCTION: !Ref GeneratePdfFunction
Events:
StateChangedTopic:
Type: SNS
Properties:
Topic: !Ref StateChangedSNSTopic
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref DocumentsDBTable
- LambdaInvokePolicy:
FunctionName: !Ref RenderTemplateFunction
- LambdaInvokePolicy:
FunctionName: !Ref GeneratePdfFunction
RenderTemplateFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 'app/render_template/'
Handler: lambda.RenderTemplate.handler
Layers:
- !Ref RenderTemplateRubyGemsLayer
Policies:
- S3CrudPolicy:
BucketName: !Ref S3Bucket
- SNSPublishMessagePolicy:
TopicName: !GetAtt StateChangedSNSTopic.TopicName
RenderTemplateRubyGemsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: render-template-gems
ContentUri: layers/render_template/
CompatibleRuntimes:
- ruby2.5
RetentionPolicy: Delete
GeneratePdfFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: 'app/generate_pdf/'
Handler: lambda.GeneratePdf.handler
MemorySize: 1536
Timeout: 15
Layers:
- arn:aws:lambda:ap-southeast-2:764866452798:layer:libreoffice:1
- !Ref GeneratePdfRubyGemsLayer
Policies:
- S3CrudPolicy:
BucketName: !Ref S3Bucket
- SNSPublishMessagePolicy:
TopicName: !GetAtt StateChangedSNSTopic.TopicName
GeneratePdfRubyGemsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: generage-pdf-gems
ContentUri: layers/generate_pdf/
CompatibleRuntimes:
- ruby2.5
RetentionPolicy: Delete
SharedLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: shared
ContentUri: layers/shared/
CompatibleRuntimes:
- ruby2.5
RetentionPolicy: Delete
S3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
BucketName: !Sub "${Product}-${Environment}"
BucketEncryption:
ServerSideEncryptionConfiguration:
-
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
LifecycleConfiguration:
Rules:
-
ExpirationInDays: 14
Status: Enabled
DocumentsDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
StreamSpecification:
StreamViewType: NEW_IMAGE
TimeToLiveSpecification:
AttributeName: ttl
Enabled: true
DocumentCreatedSNSTopic:
Type: AWS::SNS::Topic
StateChangedSNSTopic:
Type: AWS::SNS::Topic
DocumentCreatedSNSTopicSSMParameter:
Type: AWS::SSM::Parameter
Properties:
Description : "DocumentCreated SNS Topic"
Name: !Sub "/${Product}/${Environment}/DOCUMENT_CREATED_SNS_TOPIC"
Type: String
Value: !Ref DocumentCreatedSNSTopic
ApiGatewayEndpointSSMParameter:
Type: AWS::SSM::Parameter
Properties:
Description : "Api Endpoint"
Name: !Sub "/${Product}/${Environment}/API_ENDPOINT"
Type: String
Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${Environment}"
Outputs:
ApiEndpoint:
Description: "El Templito API endpoint"
Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${Environment}"