-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
166 lines (162 loc) · 5.08 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Advanced Passion for Parking
Parameters:
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- test
- preprod
- prod
Description: Environment
Platform:
Type: String
AllowedValues:
- parking
- enforcement
Description: platform information
System:
Type: String
Description: System information
Subsystem:
Type: String
Description: Subsystem information
Version:
Type: String
Description: Version information
VerifyFunctionName:
Type: String
Description: Version information
Default: 'verify'
ProcessorFunctionName:
Type: String
Description: Version information
Default: 'processor'
Globals:
Function:
Environment:
Variables:
Application__Version: !Ref Version
Application__Environment: !Ref Environment
Application__System: !Ref System
Application__Subsystem: !Ref Subsystem
Application__Platform: !Ref Platform
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, "lambdarole"] ]
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, "lambda_policy_sqs"] ]
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: SQSAccess
Effect: Allow
Action:
- "sqs:ChangeMessageVisibility"
- "sqs:DeleteMessage"
- "sqs:GetQueue*"
- "sqs:PurgeQueue"
- "sqs:ReceiveMessage"
- "sqs:SendMessage"
- "sqs:SendMessageBatch"
Resource:
- !Sub arn:aws:sqs:${AWS::Region}:${AWS::AccountId}:${Environment}-${Platform}-${System}-${Subsystem}*
- PolicyName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, "lambda_policy_dynamodb"] ]
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: DynamoDBAccess
Effect: Allow
Action:
- "dynamodb:BatchGet*"
- "dynamodb:DescribeStream"
- "dynamodb:DescribeTable"
- "dynamodb:Get*"
- "dynamodb:Query"
- "dynamodb:Scan"
- "dynamodb:BatchWrite*"
- "dynamodb:DeleteItem"
- "dynamodb:UpdateItem"
- "dynamodb:PutItem"
Resource:
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${Environment}-${Platform}-${System}-${Subsystem}-*
WebApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Environment
VerifyFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt LambdaRole.Arn
Runtime: nodejs12.x
MemorySize: 128
Timeout: 10
CodeUri: src/verify/
Handler: app.lambda_handler
FunctionName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, !Ref VerifyFunctionName] ]
Environment:
Variables:
Application__Name: !Ref VerifyFunctionName
Events:
PostEndpoint:
Type: Api
Properties:
RestApiId: !Ref WebApi
Path: /verify
Method: GET
SqsQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, "in"] ]
DelaySeconds: 0
ReceiveMessageWaitTimeSeconds: 0
MaximumMessageSize: 262144
ProcessorFunction:
Type: AWS::Serverless::Function
Properties:
Role: !GetAtt LambdaRole.Arn
Runtime: nodejs12.x
MemorySize: 512
Timeout: 5
ReservedConcurrentExecutions: 1
CodeUri: src/processor/
Handler: app.lambda_handler
FunctionName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, !Ref ProcessorFunctionName] ]
Environment:
Variables:
Application__Name: !Ref ProcessorFunctionName
Events:
MySQSEvent:
Type: SQS
Properties:
Queue: !GetAtt SqsQueue.Arn
BatchSize: 10
EnforcementTable:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: !Join [ '-', [!Ref Environment, !Ref Platform, !Ref System, !Ref Subsystem, "enforcement"] ]
AttributeDefinitions:
- AttributeName: parkId
AttributeType: S
KeySchema:
- AttributeName: parkId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Outputs:
ApiGatewayUrl:
Description: "API endpoint"
Value: !Sub "https://${WebApi}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/"