This repository was archived by the owner on Jun 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtemplate.yaml
161 lines (142 loc) · 4.06 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Parameters:
AmazonMQHost:
Type: String
Default: ''
Description: Host name of your Amazon MQ instance
AmazonMQLogin:
Type: String
Default: ''
Description: Login / username for your Amazon MQ instance
AmazonMQPassword:
Type: String
Default: ''
NoEcho: true
Description: Password for your Amazon MQ instance
AmazonMQQueueName:
Type: String
Default: SAMPLE_QUEUE
Description: Name of queue
AmazonMQSecurityGroupId:
Type: AWS::EC2::SecurityGroup::Id
Description: Security Group ID for Amazon MQ broker
Resources:
SubscriberFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: subscriber/
Handler: index.handler
Runtime: nodejs6.10
Role: !GetAtt SubscriberRole.Arn
Description: 'Polls Amazon MQ broker for messages and pushes to worker function'
Timeout: 15
Environment:
Variables:
HOST: !Ref AmazonMQHost
LOGIN: !Ref AmazonMQLogin
PASSWORD: !Ref AmazonMQPassword
QUEUE_NAME: !Ref AmazonMQQueueName
WORKER_FUNCTION: !Ref WorkerFunction
Events:
Timer:
Type: Schedule
Properties:
Schedule: rate(5 minutes)
WorkerFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: worker/
Handler: index.handler
Runtime: nodejs6.10
Role: !GetAtt WorkerRole.Arn
Description: 'Writes incoming message to DynamoDB'
Environment:
Variables:
TABLE_NAME: !Ref MessagesTable
MessagesTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: uuid
Type: String
# --------------
# add inbound to STOMP for provided security group
BrokerSGIngressFromLambda:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref AmazonMQSecurityGroupId
IpProtocol: tcp
FromPort: 61614
ToPort: 61614
CidrIp: '0.0.0.0/0'
# --------------
SubscriberRole:
Type: AWS::IAM::Role
Properties:
Path: "/AmazonMQLambda/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: AllowLambdaServiceToAssumeRole
Effect: Allow
Action:
- sts:AssumeRole
Principal:
Service:
- lambda.amazonaws.com
SubscriberPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: AmazonMQLambdaSubscriberPolicy
Roles:
- !Ref SubscriberRole
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Resource: !GetAtt WorkerFunction.Arn
Action:
- "lambda:InvokeFunction"
WorkerRole:
Type: AWS::IAM::Role
Properties:
Path: "/AmazonMQLambda/"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: AllowLambdaServiceToAssumeRole
Effect: Allow
Action:
- sts:AssumeRole
Principal:
Service:
- lambda.amazonaws.com
WorkerPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: AmazonMQLambdaWorkerPolicy
Roles:
- !Ref WorkerRole
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Resource: !GetAtt MessagesTable.Arn
Action:
- "dynamodb:PutItem"
Outputs:
MessagesTable:
Description: Name of messages table
Value: !Ref MessagesTable