-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.yaml
217 lines (205 loc) · 6.2 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Manage your S3 buckets
Globals:
Function:
Timeout: 10
Layers:
- arn:aws:lambda:us-east-1:234138278568:layer:analytics-extension:8
Environment:
Variables:
ANALYTICS_SQS_URL: !Ref AnalyticsSQS
Resources:
RootApiRust:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Auth:
DefaultAuthorizer: LambdaRequestAuthorizer
Authorizers:
LambdaRequestAuthorizer:
FunctionArn: !GetAtt AuthorizerRust.Arn
FunctionPayloadType: REQUEST
Identity:
Headers:
- Authorization
RootApiPython:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Auth:
DefaultAuthorizer: LambdaRequestAuthorizer
Authorizers:
LambdaRequestAuthorizer:
FunctionArn: !GetAtt AuthorizerPython.Arn
FunctionPayloadType: REQUEST
Identity:
Headers:
- Authorization
AuthorizerPython:
Type: AWS::Serverless::Function
Properties:
CodeUri: authorizer_python/
Handler: app.lambda_handler
Runtime: python3.11
Policies:
- DynamoDBReadPolicy:
TableName: !Ref UsersTable
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: auth
LOG_LEVEL: INFO
USERS_TABLE_NAME: !Ref UsersTable
Architectures:
- x86_64
AuthorizerRust:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: rust-cargolambda
Properties:
CodeUri: ./authorizer_rust
Handler: bootstrap
Runtime: provided.al2
Policies:
- DynamoDBReadPolicy:
TableName: !Ref UsersTable
Environment:
Variables:
USERS_TABLE_NAME: !Ref UsersTable
Architectures:
- x86_64
ListBucketsPython:
Type: AWS::Serverless::Function
Properties:
CodeUri: list_buckets_python/
Handler: app.lambda_handler
Runtime: python3.11
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:GetBucketLocation
Resource: "*"
Architectures:
- x86_64
Events:
ListBcuketsPython:
Type: Api
Properties:
RestApiId: !Ref RootApiPython
Path: /buckets-python
Method: get
ListBucketsNode:
Type: AWS::Serverless::Function
Properties:
CodeUri: list-buckets-node/
Handler: app.lambdaHandler
Runtime: nodejs20.x
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:GetBucketLocation
Resource: "*"
Architectures:
- x86_64
Events:
ListBucketsNode:
Type: Api
Properties:
RestApiId: !Ref RootApiPython
Path: /buckets-node
Method: get
ListBucketsRustNode:
Type: AWS::Serverless::Function
Properties:
CodeUri: list-buckets-rust-node/
Handler: app.lambdaHandler
Runtime: nodejs20.x
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:GetBucketLocation
Resource: "*"
Architectures:
- x86_64
Events:
ListBucketsRustNode:
Type: Api
Properties:
RestApiId: !Ref RootApiRust
Path: /buckets-rust-node
Method: get
ListBucketsRustPython:
Type: AWS::Serverless::Function
Properties:
CodeUri: list_buckets_rust_python/
Handler: app.lambda_handler
Runtime: python3.11
Policies:
- Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListAllMyBuckets
- s3:GetBucketLocation
Resource: "*"
Architectures:
- x86_64
Events:
ListBucketsRustPython:
Type: Api
Properties:
RestApiId: !Ref RootApiRust
Path: /buckets-rust-python
Method: get
GetS3Details:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: get-s3-details-node/
Handler: app.lambdaHandler
Runtime: nodejs18.x
Architectures:
- x86_64
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt AnalyticsSQS.QueueName
Events:
GetS3Details:
Type: Api
Properties:
RestApiId: !Ref RootApiRust
Path: /get-bucket
Method: get
UsersTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: user
AttributeType: S
KeySchema:
- AttributeName: user
KeyType: HASH
BillingMode: PAY_PER_REQUEST
AnalyticsSQS:
Type: AWS::SQS::Queue
Outputs:
S3AdminApiListNode:
Value: !Sub "curl -u 'admin:CTax;#+9+X3T%|z' https://${RootApiPython}.execute-api.${AWS::Region}.amazonaws.com/Prod/buckets-node"
S3AdminApiListPython:
Value: !Sub "curl -u 'admin:CTax;#+9+X3T%|z' https://${RootApiPython}.execute-api.${AWS::Region}.amazonaws.com/Prod/buckets-python"
S3AdminApiListRust:
Value: !Sub "curl -u 'admin:CTax;#+9+X3T%|z' https://${RootApiRust}.execute-api.${AWS::Region}.amazonaws.com/Prod/buckets-rust-python"
S3AdminApiListNodeRust:
Value: !Sub "curl -u 'admin:CTax;#+9+X3T%|z' https://${RootApiRust}.execute-api.${AWS::Region}.amazonaws.com/Prod/buckets-rust-node"
GetS3DetailsNode:
Value: !Sub "curl -u 'admin:CTax;#+9+X3T%|z' https://${RootApiRust}.execute-api.${AWS::Region}.amazonaws.com/Prod/get-bucket"
DynamoDB:
Value: !Sub "aws dynamodb put-item --table-name ${UsersTable} --item '{\"user\": {\"S\": \"admin\"}, \"password\": {\"S\": \"CTax;#+9+X3T%|z\"}}' --return-consumed-capacity TOTAL"