-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
344 lines (327 loc) · 10.2 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
Transform: AWS::Serverless-2016-10-31
Parameters:
environment:
Type: AWS::SSM::Parameter::Value<String>
Default: environment
prefix:
Type: AWS::SSM::Parameter::Value<String>
Default: prefix
subnetA:
Type: AWS::SSM::Parameter::Value<String>
Default: /subnet/private/a
subnetB:
Type: AWS::SSM::Parameter::Value<String>
Default: /subnet/private/b
vpc:
Type: AWS::SSM::Parameter::Value<String>
Default: vpc
AppName:
Description: Name of Application
Type: String
Default: ede-apis
Globals:
Function:
MemorySize: 128
Handler: lambda_handler.index
Runtime: python3.9
Timeout: 20
Environment:
Variables:
REGION: !Ref "AWS::Region"
Resources:
##########################################################################
# API Gateway HTTP API #
##########################################################################
# StatusHttpApi:
# Type: 'AWS::ApiGatewayV2::Api'
# Properties:
# Name: !Ref AppName
# Description: An Amazon API Gateway HTTP API and an AWS Lambda function.
# ProtocolType: HTTP
# CorsConfiguration:
# AllowOrigins:
# - '*'
# AllowMethods:
# - GET
# Target: !GetAtt StatusAPIFunction.Arn
#
# StatusRoute:
# Type: AWS::ApiGatewayV2::Route
# Properties:
# ApiId: !Ref StatusHttpApi
# RouteKey: 'GET /status'
# BasicAWSApiGateway:
# Type: AWS::Serverless::Api
# Properties:
# Name: Basic AWS Api Gateway
# StageName: Staging
#
###########################################################################
## Lambda Function #
###########################################################################
# StatusAPIFunction:
# Type: 'AWS::Serverless::Function'
# Properties:
# Handler: index.lambda_entrypoint
# CodeUri: ./src/apis/status-api/
# Role: !GetAtt LambdaRole.Arn
# VpcConfig:
# SecurityGroupIds:
# - !Ref LambdaSG
# SubnetIds:
# - !Ref subnetB
# - !Ref subnetA
# Events:
# HelloWorldApi:
# Type: Api
# Properties:
# RestApiId: !Ref BasicAWSApiGateway
# Path: /v1/ede/status
# Method: GET
# # Function permissions grant an AWS service or another account permission to use a function
# FunctionResourcePermission:
# Type: 'AWS::Lambda::Permission'
# Properties:
# Action: 'lambda:InvokeFunction'
# Principal: apigateway.amazonaws.com
# FunctionName: !Ref StatusAPIFunction
# SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${BasicAWSApiGateway}/*'
##########################################################################
# CloudFront::CachePolicy #
##########################################################################
# 3hCachePolicy:
# Type: AWS::CloudFront::CachePolicy
# Properties:
# CachePolicyConfig:
# Comment: Cache for 3h
# Name: !Ref AWS::StackName
# DefaultTTL: 600
# MaxTTL: 10800
# MinTTL: 600
# ParametersInCacheKeyAndForwardedToOrigin:
# CookiesConfig:
# CookieBehavior: none
# EnableAcceptEncodingBrotli: false
# EnableAcceptEncodingGzip: false
# HeadersConfig:
# HeaderBehavior: whitelist
# Headers:
# - x-forwarded-for
# QueryStringsConfig:
# QueryStringBehavior: whitelist
# QueryStrings:
# - allowed_query_string_param
#
###########################################################################
## CloudFront::Distribution #
###########################################################################
# CloudfrontDistribution:
# Type: AWS::CloudFront::Distribution
# Properties:
# DistributionConfig:
# PriceClass: PriceClass_100
# IPV6Enabled: true
# HttpVersion: http2
# Origins:
# - Id: MyOrigin
# DomainName: !Sub "${AppName }.execute-api.${AWS::Region}.amazonaws.com"
# OriginPath: /ede
# CustomOriginConfig:
# HTTPSPort: 443
# OriginProtocolPolicy: https-only
# OriginSSLProtocols:
# - TLSv1.2
# Enabled: true
# DefaultCacheBehavior:
# AllowedMethods:
# - GET
# - HEAD
# CachedMethods:
# - GET
# - HEAD
# Compress: true
# TargetOriginId: MyOrigin
# ViewerProtocolPolicy: redirect-to-https
# CachePolicyId: !Ref 3hCachePolicy
#### What gets deployed:
# Lambda on a 15m schedule that checks for new smart contract events
# Other required SSM parameters:
# (RPC endpoint)
# /ede/config/mainnet
# /ede/config/gnosis
# (Contract watching)
# /ede/tasks/mainnet/<ContractName>/<Event>/<ContractAddress>
# Example:
# /ede/tasks/mainnet/ProofOfHumanity/AddSubmission/0xC5E9dDebb09Cd64DfaCab4011A0D5cEDaf7c9BDb
# This watches a ProofOfHumanity contract at 0xC5..
# todo: implement smart contract version management
# See README for further configuration
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${prefix}-${environment}-events
ABITable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: !Sub ${prefix}-${environment}-abi
SNSTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: !Sub ${prefix}-${environment}-beat
txListenerMainnet:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
TABLE: !Ref ABITable
BUCKET: !Ref Bucket
REGION: !Ref AWS::Region
SNS: !Ref SNSTopic
network: "mainnet"
provider: "infura"
FunctionName: !Sub ${prefix}-${environment}-mainnet-listener
Handler: index.lambda_entrypoint
Runtime: python3.9
MemorySize: 1028
CodeUri: ./src/event-driven-ethereum
Timeout: 360
Events:
InvocationLevel:
Type: Schedule
Properties:
Schedule: 'rate(15 minutes)'
Role: !GetAtt LambdaRole.Arn
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSG
SubnetIds:
- !Ref subnetB
- !Ref subnetA
txListenerGnosis:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
TABLE: !Ref ABITable
BUCKET: !Ref Bucket
REGION: !Ref AWS::Region
SNS: !Ref SNSTopic
network: "gnosis"
FunctionName: !Sub ${prefix}-${environment}-gnosis-listener
Handler: index.lambda_entrypoint
Runtime: python3.9
MemorySize: 1028
CodeUri: ./src/event-driven-ethereum
Timeout: 360
Events:
InvocationLevel:
Type: Schedule
Properties:
Schedule: 'rate(15 minutes)'
Role: !GetAtt LambdaRole.Arn
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSG
SubnetIds:
- !Ref subnetB
- !Ref subnetA
txListenerArbitrumRinkeby:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
TABLE: !Ref ABITable
BUCKET: !Ref Bucket
REGION: !Ref AWS::Region
SNS: !Ref SNSTopic
network: "arbitrum-rinkeby"
FunctionName: !Sub ${prefix}-${environment}-arb-rinkeby-listener
Handler: index.lambda_entrypoint
Runtime: python3.9
MemorySize: 1028
CodeUri: ./src/event-driven-ethereum
Timeout: 360
Events:
InvocationLevel:
Type: Schedule
Properties:
Schedule: 'rate(15 minutes)'
Role: !GetAtt LambdaRole.Arn
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSG
SubnetIds:
- !Ref subnetB
- !Ref subnetA
LambdaSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: txListener
VpcId: !Ref vpc
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 80
ToPort: 8545
CidrIp: 0.0.0.0/0
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- ec2:CreateNetworkInterface
- ssm:GetParameter*
- ec2:DescribeNetworkInterfaces
- ec2:DeleteNetworkInterface
- ssm:ListTagsForResource
- events:ListRules
- events:Put*
- sns:Publish
- sqs:SendMessage
Resource: '*'
- Effect: Allow
Action:
- ssm:*
Resource: 'arn:aws:ssm:*:*:parameter/ede/*'
- Effect: Allow
Action:
- dynamodb:* # FIX ME // NARROW SCOPE
#Resource: !Sub "arn:aws:dynamodb:*:*:table/${ABITable}"
Resource: !Sub "arn:aws:dynamodb:*:*:table/*"
- Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
- s3:GetObjectAcl
- s3:ListBucket
- s3:GetBucketLocation
Resource: !Sub "arn:aws:s3:::${Bucket}/*"
- Effect: Allow
Action:
- s3:ListBucket
Resource: !Sub "arn:aws:s3:::${Bucket}"
#Outputs:
# StatusHttpApiEndpoint:
# Description: The default endpoint for the HTTP API.
# Value: !GetAtt StatusHttpApi.ApiEndpoint
# DistributionDomainName:
# Description: "Distribution domain name"
# Value: !GetAtt CloudfrontDistribution.DomainName
# Export:
# Name: DistributionDomainName