-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.yaml
90 lines (85 loc) · 3.35 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
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Schedule or delay message publication on an AWS SNS topic using a
simple Step Functions state machine with two tasks: Wait, SNS.
Parameters:
# For demo. You can remove this and the "Subscription" section below.
NotificationEmail:
Type: String
Description: Email address to subscribe to SNS topic
Resources:
# SNS topic. Could be passed in as a parameter to the stack instead.
SNSTopic:
Type: AWS::SNS::Topic
Properties:
# For demo. You can remove this and the "Parameters" section above.
Subscription:
- Endpoint: !Ref NotificationEmail
Protocol: email
# Step Functions state machine that delays, then publishes to SNS topic.
StepFunctionsStateMachine:
Type: "AWS::StepFunctions::StateMachine"
Properties:
StateMachineName: DelayedSNS
RoleArn: !GetAtt StepFunctionsServiceRole.Arn
# Replace "SecondsPath" with "TimestampPath" for scheduling
DefinitionString:
Fn::Sub:
- |
{
"StartAt": "Delay",
"Comment": "Publish to SNS with delay",
"States": {
"Delay": {
"Type": "Wait",
"SecondsPath": "$.delay_seconds",
"Next": "Publish to SNS"
},
"Publish to SNS": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn": "${SNSTopic}",
"Subject.$": "$.subject",
"Message.$": "$.message"
},
"End": true
}
}
}
- SNSTopic: !Ref SNSTopic
# Allow Step Functions state machine to publish to SNS topic
StepFunctionsServiceRole:
Type: "AWS::IAM::Role"
Properties:
Path: !Join ["", ["/", !Ref "AWS::StackName", "/"]]
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Sid: "AllowStepFunctionsServiceToAssumeRole"
Effect: "Allow"
Action:
- "sts:AssumeRole"
Principal:
Service:
- !Sub "states.${AWS::Region}.amazonaws.com"
Policies:
- PolicyName: "PublishToSNSTopic"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: "Allow"
Action:
- "sns:Publish"
Resource:
- !Ref SNSTopic
Outputs:
StepFunctionsStateMachine:
Description: Step Functions State Machine ARN
Value: !Ref StepFunctionsStateMachine
SNSTopic:
Description: SNS Topic ARN
Value: !Ref SNSTopic