-
Notifications
You must be signed in to change notification settings - Fork 11
/
template.yaml
65 lines (61 loc) · 1.73 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
lambda-iot-rule
Parameters:
PublishTopic:
Type: String
Default: "topic_1"
Description: (Required) Provide a topic to publish on. The default will publish on topic_1
SubscribeTopic:
Type: String
Default: "topic_2"
Description: (Required) Provide a topic for the IoT rule to query. The default will trigger on any message published to topic_2
Resources:
TopicSubscriber:
Type: AWS::Serverless::Function
Properties:
Handler: app.handler
Runtime: nodejs10.x
CodeUri: src/topicSubscriber/
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyTable
Environment:
Variables:
TABLE_NAME: !Ref MyTable
Events:
IoT:
Type: IoTRule
Properties:
AwsIotSqlVersion: 2016-03-23
Sql: !Sub "SELECT * FROM '${SubscribeTopic}'"
TopicPublisher:
Type: AWS::Serverless::Function
Properties:
Handler: app.handler
Runtime: nodejs10.x
CodeUri: src/topicPublisher/
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- iot:Publish
- iot:DescribeEndpoint
Resource: '*'
Environment:
Variables:
PUBLISH_TOPIC: !Ref PublishTopic
Events:
PostResource:
Type: Api
Properties:
Path: /publish
Method: post
MyTable:
Type: AWS::Serverless::SimpleTable
Outputs:
ApiURL:
Description: "API endpoint URL for Prod environment"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"