forked from alestic/aws-sns-delayed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
69 lines (66 loc) · 2.62 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
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.
Resources:
# 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",
"TimestampPath": "$.delay_timestamp",
"Next": "Publish to SNS"
},
"Publish to SNS": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"TopicArn.$": "$.sns_topic",
"Message.$": "$.message"
},
"End": true
}
}
}
# 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:
- "*"
Outputs:
StepFunctionsStateMachine:
Description: Step Functions State Machine ARN
Value: !Ref StepFunctionsStateMachine