Last active
May 19, 2022 11:55
-
-
Save danielfyhr/4144dba260cc2bce1509d12cfd998664 to your computer and use it in GitHub Desktop.
Send emails once AWS Step Functions definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Comment": "Send emails only once", | |
"StartAt": "CreateHashFromEmail", | |
"States": { | |
"CreateHashFromEmail": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"InputPath": "$.email", | |
"ResultSelector": { | |
"value.$": "$.Payload" | |
}, | |
"Parameters": { | |
"Payload.$": "$", | |
"FunctionName": "arn:aws:lambda:eu-central-1:000000000000:function:CreateHash:$LATEST" | |
}, | |
"Next": "PutHashInDatabase", | |
"ResultPath": "$.hash" | |
}, | |
"PutHashInDatabase": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::dynamodb:putItem", | |
"InputPath": "$.hash", | |
"Parameters": { | |
"TableName": "emails", | |
"Item": { | |
"PK": { | |
"S.$": "$.value" | |
} | |
}, | |
"ConditionExpression": "attribute_not_exists(PK)" | |
}, | |
"Next": "SendEmail", | |
"Catch": [ | |
{ | |
"ErrorEquals": [ | |
"States.TaskFailed" | |
], | |
"Next": "IsConditionalCheckFailedException" | |
} | |
], | |
"ResultPath": null | |
}, | |
"IsConditionalCheckFailedException": { | |
"Type": "Choice", | |
"Choices": [ | |
{ | |
"Variable": "$.Error", | |
"StringEquals": "DynamoDB.ConditionalCheckFailedException", | |
"Next": "Pass", | |
"Comment": "ConditionalCheckFailedException" | |
} | |
], | |
"Default": "Fail" | |
}, | |
"Pass": { | |
"Type": "Pass", | |
"End": true | |
}, | |
"Fail": { | |
"Type": "Fail" | |
}, | |
"SendEmail": { | |
"Type": "Task", | |
"Resource": "arn:aws:states:::lambda:invoke", | |
"OutputPath": "$.Payload", | |
"InputPath": "$.email", | |
"Parameters": { | |
"Payload.$": "$", | |
"FunctionName": "arn:aws:lambda:eu-central-1:000000000000:function:SendEmail:$LATEST" | |
}, | |
"End": true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment