-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda.template
250 lines (250 loc) · 9.5 KB
/
lambda.template
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation Sample Template DynamoDB_Table: This template demonstrates the creation of a DynamoDB table. **WARNING** This template creates an Amazon DynamoDB table. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters": {
"HashKeyElementName": {
"Description": "HashType PrimaryKey Name",
"Type": "String",
"Default": "Username",
"AllowedPattern": "[a-zA-Z0-9]*",
"MinLength": "1",
"MaxLength": "2048",
"ConstraintDescription": "must contain only alphanumberic characters"
},
"HashKeyElementType": {
"Description": "HashType PrimaryKey Type",
"Type": "String",
"Default": "S",
"AllowedPattern": "[S|N]",
"MinLength": "1",
"MaxLength": "1",
"ConstraintDescription": "must be either S or N"
},
"ReadCapacityUnits": {
"Description": "Provisioned read throughput",
"Type": "Number",
"Default": "5",
"MinValue": "5",
"MaxValue": "10000",
"ConstraintDescription": "must be between 5 and 10000"
},
"WriteCapacityUnits": {
"Description": "Provisioned write throughput",
"Type": "Number",
"Default": "10",
"MinValue": "5",
"MaxValue": "10000",
"ConstraintDescription": "must be between 5 and 10000"
},
"FunctionBucket": {
"Description": "S3 Bucket with Lambda function",
"Type": "String"
},
"FunctionKey": {
"Description": "S3 Key of Lambda function",
"Type": "String"
},
"LambdaSecurityGroup": {
"Description": "Security Group ID for Lambda",
"Type": "String"
},
"SubnetIds": {
"Description": "Subnet IDs for Lambda",
"Type": "CommaDelimitedList"
}
},
"Resources": {
"myDynamoDBTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "GloboOrders",
"StreamSpecification": {
"StreamViewType": "NEW_IMAGE"
},
"AttributeDefinitions": [
{
"AttributeName": {
"Ref": "HashKeyElementName"
},
"AttributeType": {
"Ref": "HashKeyElementType"
}
},
{
"AttributeName": "Timestamp",
"AttributeType": "S"
}
],
"KeySchema": [
{
"AttributeName": {
"Ref": "HashKeyElementName"
},
"KeyType": "HASH"
},
{
"AttributeName": "Timestamp",
"KeyType": "RANGE"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": {
"Ref": "ReadCapacityUnits"
},
"WriteCapacityUnits": {
"Ref": "WriteCapacityUnits"
}
}
}
},
"orderLambdaRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"Description": "Role used by Orders Lambda function",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "orderLambdaPolicy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": {
"Fn::Join": [
":",
[
"arn:aws:logs",
{
"Ref": "AWS::Region"
},
{
"Ref": "AWS::AccountId"
},
"*"
]
]
}
},
{
"Effect": "Allow",
"Action": [
"dynamodb:DescribeStream",
"dynamodb:GetRecords",
"dynamodb:GetShardIterator",
"dynamodb:ListStreams"
],
"Resource": {
"Fn::Join": [
"",
[
{
"Fn::GetAtt": [
"myDynamoDBTable",
"Arn"
]
},
"/stream/*"
]
]
}
},
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface",
"ec2:DescribeNetworkInterfaces",
"ec2:DeleteNetworkInterface"
],
"Resource": [
"*"
]
}
]
}
}
]
}
},
"orderLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": "publishOrders",
"Description": "Lambda function for orders",
"Code": {
"S3Bucket": {
"Ref": "FunctionBucket"
},
"S3Key": {
"Ref": "FunctionKey"
}
},
"Role": {
"Fn::GetAtt": [
"orderLambdaRole",
"Arn"
]
},
"Handler": "publishOrders.handler",
"Runtime": "nodejs10.x",
"VpcConfig": {
"SecurityGroupIds": [
{
"Ref": "LambdaSecurityGroup"
}
],
"SubnetIds": {
"Ref": "SubnetIds"
}
}
}
}
},
"Outputs": {
"TableName": {
"Value": {
"Ref": "myDynamoDBTable"
},
"Description": "Table name of the newly created DynamoDB table"
},
"FunctionArn": {
"Value": {
"Fn::GetAtt": [
"orderLambdaFunction",
"Arn"
]
},
"Description": "Arn of the Lambda Function"
}
}
}