-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
121 lines (110 loc) · 3.62 KB
/
template.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
# Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
Arch:
Type: String
Default: x86_64
AllowedValues:
- arm64
- x86_64
Env:
Type: String
AllowedValues:
- test
- prod
Mappings:
EnvMapping:
test:
Arch: arm64
InboxBucket: spi-scratch-inbox
# Allow the test process to write to spi-dev-docs alternatively.
OutputBucket1: spi-scratch
OutputBucket2: spi-dev-docs
prod:
Arch: arm64
InboxBucket: spi-docs-inbox
OutputBucket1: spi-dev-docs
OutputBucket2: spi-prod-docs
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 900
Resources:
UploadFunction:
Type: AWS::Serverless::Function
Properties:
Architectures:
- !FindInMap [ EnvMapping, !Ref Env, Arch ]
CodeUri: ./.lambda/doc-uploader/lambda.zip
Handler: "haha"
Runtime: provided.al2
# https://www.sentiatechblog.com/aws-re-invent-2020-day-3-optimizing-lambda-cost-with-multi-threading
# (3009 causes error on deployment)
MemorySize: 3008
EphemeralStorage:
Size: 2048
Policies:
- AWSLambdaExecute
- Version: '2012-10-17' # Policy Document
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:GetObjectACL
- s3:DeleteObject
Resource: !Sub
- 'arn:aws:s3:::${Bucket}/*'
- Bucket: !FindInMap [ EnvMapping, !Ref Env, InboxBucket ]
- Effect: Allow
Action:
- s3:*
Resource:
- !Sub
- 'arn:aws:s3:::${Bucket}/*'
- Bucket: !FindInMap [ EnvMapping, !Ref Env, OutputBucket1 ]
- !Sub
- 'arn:aws:s3:::${Bucket}'
- Bucket: !FindInMap [ EnvMapping, !Ref Env, OutputBucket1 ]
- !Sub
- 'arn:aws:s3:::${Bucket}/*'
- Bucket: !FindInMap [ EnvMapping, !Ref Env, OutputBucket2 ]
- !Sub
- 'arn:aws:s3:::${Bucket}'
- Bucket: !FindInMap [ EnvMapping, !Ref Env, OutputBucket2 ]
Environment:
Variables:
LOG_LEVEL: info
Events:
InboxEvent:
Type: S3
Properties:
Bucket: !Ref InboxBucketResource
Events: s3:ObjectCreated:*
InboxBucketResource:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !FindInMap [ EnvMapping, !Ref Env, InboxBucket ]
LifecycleConfiguration:
Rules:
- Id: InboxExpirationRule
Status: Enabled
ExpirationInDays: 1
# explicitly create log group to ensure logs are only preserved 14 days (otherways always)
UploadFunctionLogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Sub "/aws/lambda/${UploadFunction}"
RetentionInDays: 14