Tutorial for creating lambda and step function that invokes it
Invoke syntax, parameter and payload
- Supported parameters:
ClientContext
FunctionName
InvocationType
Qualifier
Payload
-
-
- Use this design pattern any time you need to keep track of the number of loops in a state machine.
- When you invoke a Lambda function, the execution will wait for the function to complete
- State machine cloudformation code in YAML:
Resources: SFSM3E6D3: Type: 'AWS::StepFunctions::StateMachine' Properties: Comment: Iterator State Machine Example StartAt: ConfigureCount States: ConfigureCount: Type: Pass Result: count: 10 index: 0 step: 1 ResultPath: $.iterator Next: Iterator Iterator: Type: Task Resource: 'arn:aws:lambda:us-east-1:123456789012:function:Iterate' ResultPath: $.iterator Next: IsCountReached IsCountReached: Type: Choice Choices: - Variable: $.iterator.continue BooleanEquals: true Next: ExampleWork Default: Done ExampleWork: Comment: 'Your application logic, to run a specific number of times' Type: Pass Result: success: true ResultPath: $.result Next: Iterator Done: Type: Pass End: true
-
Sending failed task from state function to sqs. Sample code:
{
"StartAt": "GetMyRecords",
"States": {
"GetMyRecords": {
"Type": "Task",
"Resource": "",
"TimeoutSeconds": 80,
"Retry": [
{
"ErrorEquals": [
"CustomError"
],
"IntervalSeconds": 300,
"MaxAttempts": 10,
"BackoffRate": 1.1
}
],
"Catch": [
{
"ErrorEquals": [
"CustomError"
],
"Next": "SendToSQS",
"ResultPath": "$.error"
}
],
"End": true
},
"SendToSQS": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage",
"Parameters": {
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/myQueue",
"MessageBody.$": "$.input.message",
"MessageAttributes": {
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 1"
},
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 2"
}
}
},
"End": true
}
}
}