import json
def lambda_handler(event, context):
input_data = event['Input']
output_data = {
'result': input_data * 2
}
return {
"statusCode": 200,
"body": json.dumps(output_data)
}
{
"Comment": "Map State Machine Example",
"StartAt": "MapState",
"States": {
"MapState": {
"Type": "Map",
"ItemsPath": "$.input",
"Iterator": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:0123456789:function:MyLambdaFunction",
"ResultPath": "$.result",
"Retry": [
{
"ErrorEquals": [
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "CatchState"
}
]
},
"End": true
},
"CatchState": {
"Type": "Fail",
"Error": "States.ALL",
"Cause": "An error occurred while processing the Map State Machine."
}
}
}
{
"input": [1, 2, 3, 4, 5]
}
使用上述三个步骤,就可以使用AWS Step Functions的Map State Machine,并测试一次迭代。