-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.yaml
178 lines (167 loc) · 4.8 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: your-cat
Parameters:
ResourcePrefix:
Type: String
Default: yourcat
EnvironmentName:
Type: String
AllowedValues:
- dev
- prd
ApiAllowOrigin:
Type: String
Conditions:
IsPrd: !Equals [!Ref EnvironmentName, prd]
Globals:
Function:
MemorySize: 1024
Timeout: 30
Environment:
Variables:
LOG_LEVEL: !If [IsPrd, INFO, DEBUG]
ENV_NAME: !Sub ${EnvironmentName}
RUST_BACKTRACE: 1
API_ALLOW_ORIGIN: !Sub ${ApiAllowOrigin}
Resources:
ImageS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${ResourcePrefix}-${EnvironmentName}-image
CorsConfiguration:
CorsRules:
- AllowedMethods:
- GET
AllowedOrigins:
- '*'
ImageS3BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref ImageS3Bucket
PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- 's3:GetObject'
Effect: Allow
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref ImageS3Bucket
- /*
Principal: '*'
ImageDataCacheBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${ResourcePrefix}-${EnvironmentName}-image-data-cache
RestApis:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${ResourcePrefix}-${EnvironmentName}
StageName: !Sub ${ResourcePrefix}-${EnvironmentName}-apis
Cors:
AllowOrigin: !Sub "'${ApiAllowOrigin}'"
AllowHeaders: "'Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token'"
AllowMethods: "'POST, OPTIONS'"
GetPhotosFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: rust-cargolambda
BuildProperties:
Binary: get_photos
Properties:
FunctionName: !Sub ${ResourcePrefix}-${EnvironmentName}-get-photos
CodeUri: "."
Handler: bootstrap
Runtime: provided.al2
Policies:
- S3FullAccessPolicy:
BucketName: !Ref ImageDataCacheBucket
Environment:
Variables:
CACHE_BUCKET_NAME: !Ref ImageDataCacheBucket
Events:
RestApis:
Type: Api
Properties:
RestApiId: !Ref RestApis
Path: /get-image
Method: GET
IsTheCatFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: rust-cargolambda
BuildProperties:
Binary: is_the_cat
Properties:
FunctionName: !Sub ${ResourcePrefix}-${EnvironmentName}-is-the-cat
CodeUri: "."
Handler: bootstrap
Runtime: provided.al2
Policies:
- RekognitionDetectOnlyPolicy: {}
Events:
RestApis:
Type: Api
Properties:
RestApiId: !Ref RestApis
Path: /is-the-cat
Method: post
PostPhotoFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: rust-cargolambda
BuildProperties:
Binary: post_photo
Properties:
FunctionName: !Sub ${ResourcePrefix}-${EnvironmentName}-post-photo
CodeUri: "."
Handler: bootstrap
Runtime: provided.al2
Policies:
- S3FullAccessPolicy:
BucketName: !Ref ImageS3Bucket
- S3FullAccessPolicy:
BucketName: !Ref ImageDataCacheBucket
- DynamoDBCrudPolicy:
TableName: !Sub ${ResourcePrefix}-${EnvironmentName}-image
- LambdaInvokePolicy:
FunctionName: !Sub ${ResourcePrefix}-${EnvironmentName}-tweet
Environment:
Variables:
IMAGE_BUCKET_NAME: !Ref ImageS3Bucket
CACHE_BUCKET_NAME: !Ref ImageDataCacheBucket
IMAGE_TABLE_NAME: !Sub ${ResourcePrefix}-${EnvironmentName}-image
INVOKE_LAMBDA_NAME: !Sub ${ResourcePrefix}-${EnvironmentName}-tweet
Events:
RestApis:
Type: Api
Properties:
RestApiId: !Ref RestApis
Path: /post-image
Method: POST
TweetFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ResourcePrefix}-${EnvironmentName}-tweet
CodeUri: twitter/
Handler: tweet.lambda_handler
Runtime: python3.9
Policies:
- S3FullAccessPolicy:
BucketName: !Ref ImageS3Bucket
Environment:
Variables:
IMAGE_BUCKET_NAME: !Ref ImageS3Bucket
ImageDataDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub ${ResourcePrefix}-${EnvironmentName}-image
KeySchema:
- AttributeName: file_id
KeyType: HASH
AttributeDefinitions:
- AttributeName: file_id
AttributeType: S
BillingMode: PAY_PER_REQUEST