-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudformation.yml
156 lines (146 loc) · 6 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
AWSTemplateFormatVersion: "2010-09-09"
Description: "Deploys an API gateway you can use with VoltValet to receive status information from your EVSE"
Parameters:
MyEmail:
Description: Email for station notifications
Type: String
AllowedPattern: '[^@]+@[^@]+\.[^@]+'
ChargerName:
Description: Name of your charger
Type: String
Outputs:
ConnectURL:
Description: URL to paste into your code for the AVR-IoT Cellular Mini.
Value: !Sub "${ApiGatewayRestApi}.execute-api.us-east-2.amazonaws.com"
TopicARN:
Description: ARN to paste into your code for the AVR-IoT Cellular Mini.
Value: !Ref SNSTopic
Resources:
IAMRole:
Type: "AWS::IAM::Role"
Properties:
Path: "/"
RoleName: !Sub "${SNSTopic.TopicName}PublishRole"
AssumeRolePolicyDocument: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"apigateway.amazonaws.com\",\"sns.amazonaws.com\"]},\"Action\":\"sts:AssumeRole\"}]}"
MaxSessionDuration: 3600
ManagedPolicyArns:
- !Ref IAMManagedPolicy
- "arn:aws:iam::aws:policy/service-role/AmazonSNSRole"
Description: "Allows SNS to call CloudWatch Logs on your behalf."
IAMManagedPolicy:
Type: "AWS::IAM::ManagedPolicy"
Properties:
ManagedPolicyName: "VoltValetPublishPolicy"
Path: "/"
PolicyDocument: |
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
SNSTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: !Ref ChargerName
TopicName: !Ref ChargerName
SNSTopicPolicy:
Type: "AWS::SNS::TopicPolicy"
Properties:
PolicyDocument: !Sub "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\"],\"Resource\":\"${SNSTopic}\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"${AWS::AccountId}\"}}}]}"
Topics:
- !Ref SNSTopic
SNSSubscription:
Type: "AWS::SNS::Subscription"
Properties:
TopicArn: !Ref SNSTopic
Endpoint: !Ref MyEmail
Protocol: "email"
Region: "us-east-2"
ApiGatewayRestApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: "VoltValet"
ApiKeySourceType: "HEADER"
EndpointConfiguration:
Types:
- "EDGE"
ApiGatewayResource:
Type: "AWS::ApiGateway::Resource"
Properties:
RestApiId: !Ref ApiGatewayRestApi
PathPart: "charger"
ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
ApiGatewayMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref ApiGatewayRestApi
ResourceId: !Ref ApiGatewayResource
HttpMethod: "POST"
AuthorizationType: "NONE"
ApiKeyRequired: false
RequestParameters:
"method.request.querystring.message": true
"method.request.querystring.topic": true
RequestModels:
"application/json": !Ref ApiGatewayModel
MethodResponses:
-
ResponseModels:
"application/json": "Empty"
StatusCode: "200"
Integration:
CacheNamespace: !Ref ApiGatewayResource
Credentials: !GetAtt IAMRole.Arn
IntegrationHttpMethod: "POST"
IntegrationResponses:
-
ResponseTemplates: {}
StatusCode: "200"
PassthroughBehavior: "WHEN_NO_MATCH"
RequestParameters:
"integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
"integration.request.querystring.Message": "method.request.querystring.message"
"integration.request.querystring.TopicArn": "method.request.querystring.topic"
RequestTemplates:
"application/json": !Sub |
#set($topic="${SNSTopic}")
#set($msg=$input.path('$.message'))
Action=Publish&TopicArn=$util.urlEncode($topic)&Message=$util.urlEncode($msg)
TimeoutInMillis: 29000
Type: "AWS"
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:sns:path/arn:aws:apigateway:us-east-2:sns:path//*"
ApiGatewayDeployment:
Type: "AWS::ApiGateway::Deployment"
DependsOn: ApiGatewayMethod
Properties:
RestApiId: !Ref ApiGatewayRestApi
ApiGatewayStage:
Type: "AWS::ApiGateway::Stage"
Properties:
StageName: "prod"
DeploymentId: !Ref ApiGatewayDeployment
RestApiId: !Ref ApiGatewayRestApi
CacheClusterEnabled: false
CacheClusterSize: "0.5"
TracingEnabled: false
ApiGatewayModel:
Type: "AWS::ApiGateway::Model"
Properties:
RestApiId: !Ref ApiGatewayRestApi
Name: "ChargerPublishModel"
Schema: |
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "ChargerPublishModel",
"type": "object",
"properties": {
"message": {"type": "string"}
}
}
ContentType: "application/json"