-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate.yml
133 lines (123 loc) · 4.05 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
AWSTemplateFormatVersion: 2010-09-09
Description: >-
crypto-bot-parrot
Transform:
- AWS::Serverless-2016-10-31
Parameters:
LogLevelParameter:
Type: String
Description: Functions log level
Default: info
AllowedValues:
- debug
- info
EnvironmentParameter:
Type: String
Description: Environment where the stack is deployed
Default: test
AllowedValues:
- test
- prod
TracingParameter:
Description: Boolean to enable or disable tracing
Type: String
Default: false
ExchangesSecretNameParameter:
Description: Name of the exchanges secret stored in Secrets Manager
Type: String
ExchangesSecretEncryptionKeyParameter:
Description: Encryption key used to encrypt the exchanges secret in Secrets Manager (either a key id 'key/xxx' or an alias 'alias/xxx')
Type: String
Default: alias/aws/secretsmanager
Conditions:
TracingCondition: !Equals [ !Ref TracingParameter, true ]
Mappings:
EnvironmentMap:
test:
Strategy: '{ "exchange": "Binance", "symbol": "BTC#BUSD", "quantity": 50, "assets": [ { "asset": "ETH|BNB", "percentage": 0.50 } ] }'
StrategySchedule: cron(0 18 ? * * *)
prod:
Strategy: '{ "exchange": "Binance", "symbol": "BTC#EUR", "quantity": 25, "assets": [ { "asset": "ETH", "percentage": 0.26 }, { "asset": "ADA|BNB|MATIC", "percentage": 0.24 }, { "asset": "AVAX|EGLD|SOL", "percentage": 0.24 } ] }'
StrategySchedule: cron(0 18 ? * 1 *)
Globals:
Function:
Runtime: nodejs16.x
MemorySize: 128
Timeout: 30
AutoPublishAlias: Live
Tracing: !If [ TracingCondition, Active, PassThrough ]
Environment:
Variables:
LOG_LEVEL: !Ref LogLevelParameter
ENV: !Ref EnvironmentParameter
REGION: !Ref AWS::Region
TRACING: !Ref TracingParameter
Resources:
ExecuteStrategyFunction:
Type: AWS::Serverless::Function
Properties:
Description: Execute strategy function
CodeUri: src/handlers
Handler: execute-strategy-handler.handler
ReservedConcurrentExecutions: 1
Environment:
Variables:
EXCHANGES_SECRET_NAME: !Ref ExchangesSecretNameParameter
STRATEGY_TABLE_NAME: !Ref StrategyTable
STRATEGY: !FindInMap [ EnvironmentMap, !Ref EnvironmentParameter, Strategy ]
Events:
ScheduleEvent:
Type: Schedule
Properties:
Enabled: true
Schedule: !FindInMap [ EnvironmentMap, !Ref EnvironmentParameter, StrategySchedule ]
Policies:
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${ExchangesSecretNameParameter}*
- Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- kms:Decrypt
Resource: !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:${ExchangesSecretEncryptionKeyParameter}
- DynamoDBReadPolicy:
TableName: !Ref StrategyTable
- DynamoDBWritePolicy:
TableName: !Ref StrategyTable
Metadata:
BuildMethod: esbuild
BuildProperties:
Target: es2021
Minify: true
SourceMap: true
EntryPoints:
- execute-strategy-handler.ts
StrategyTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: true
KeySchema:
- AttributeName: pk
KeyType: HASH
- AttributeName: sk
KeyType: RANGE
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
- AttributeName: sk
AttributeType: S
Outputs:
ExecuteStrategyFunctionName:
Description: Execute strategy function name
Value: !Ref ExecuteStrategyFunction
ExecuteStrategyFunctionArn:
Description: Execute strategy function ARN
Value: !GetAtt ExecuteStrategyFunction.Arn
StrategyTableName:
Description: Strategy table name
Value: !Ref StrategyTable
StrategyTableArn:
Description: Strategy table ARN
Value: !GetAtt StrategyTable.Arn