Invoking the first Lambda function with an AWS API Gateway. Once the first Lambda function receives the incoming request from the API Gateway, it will validate the request and start the Step Function State Machine. The AWS Step Function State Machine will trigger the second Lambda Function if the transaction_type
is either PURCHASE
or REJECTED
.
The second Lambda Function will receive the event as JSON text as the input and will process the received event (json.RawMessage
). It is because the individual states receive JSON as input and usually pass JSON as output to the next state.
{
"StartAt": "processTransactionTask",
"States": {
"processTransactionTask": {
"End": true,
"Type": "Task",
"InputPath": "$",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "arn:aws:lambda:region:account_id:function:processTransaction",
"Payload.$": "$"
}
}
}
}
When the API received an incoming request, it will validate if the required fields are present, start the Step Function State Machine, and will return an HTTP Status OK.
Method: POST
Endpoint: https://{api-id}.execute.api.{region}.amazonaws.com/prod/
Request Body
{
"customerId": "84378220428",
"card_number": "4444 4444 8888 8888",
"transaction_type": "PURCHASE"
}
- States
- Amazon States Language
- AWS Step Function Guides
- Input and Output Processing in Step Functions
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
-
Install all the dependencies, bootstrap your project, and synthesized CloudFormation template.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-lambda$ make init # With "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-lambda$ make init profile=[profile_name]
-
Deploy the project.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-lambda$ make deploy # With "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-lambda$ make deploy profile=[profile_name]