This repository has been archived by the owner on Nov 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudformation.yml
167 lines (152 loc) · 3.42 KB
/
cloudformation.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
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
DeployBucketName:
Type: String
Default: mke-trash-pickup
DeployKeyName:
Type: String
Default: mke-trash-pickup.zip
LambdaHandler:
Type: String
Default: refusereminder.lambda_handler
SNSTopicName:
Type: String
Default: mke-trash-pickup
Frequency:
Type: String
Default: '12 hours'
Description: 'See here for details: http://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html'
AddressNumber:
Type: String
AddressDirection:
Type: String
AllowedValues:
- N
- S
- E
- W
StreetName:
Type: String
StreetType:
Type: String
Default: ST
AllowedValues:
- AV
- BL
- CR
- CT
- DR
- LA
- PK
- PL
- RD
- SQ
- ST
- TR
- WY
Resources:
DataBucket:
Type: 'AWS::S3::Bucket'
LambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: '/'
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:*
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:PutObjectAcl
Resource:
'Fn::Join':
- ''
- - 'arn:aws:s3:::'
- Ref: DataBucket
- '/*'
- Effect: Allow
Action:
- sns:Publish
Resource:
Ref: SNSTopic
LambdaJob:
Type: 'AWS::Lambda::Function'
Properties:
Handler:
Ref: LambdaHandler
Role:
'Fn::GetAtt':
- LambdaExecutionRole
- Arn
Code:
S3Bucket:
Ref: DeployBucketName
S3Key:
Ref: DeployKeyName
Runtime: python3.6
Timeout: 45
SNSTopic:
Type: 'AWS::SNS::Topic'
Properties:
TopicName:
Ref: SNSTopicName
EventRule:
Type: 'AWS::Events::Rule'
Properties:
ScheduleExpression: "rate(12 hours)"
ScheduleExpression:
'Fn::Join':
- ''
- - 'rate('
- Ref: Frequency
- ')'
Targets:
- Id: GarbageCheckScheduler
Arn:
'Fn::GetAtt':
- LambdaJob
- Arn
Input:
'Fn::Join':
- ''
- - '{'
- '"s3_bucket": "'
- Ref: DataBucket
- '", "house_number": "'
- Ref: AddressNumber
- '", "direction": "'
- Ref: AddressDirection
- '", "street_name": "'
- Ref: StreetName
- '", "street_type": "'
- Ref: StreetType
- '" }'
InvokeLambdaPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName:
'Fn::GetAtt':
- LambdaJob
- Arn
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceArn:
'Fn::GetAtt':
- EventRule
- Arn