I want a sample to integrate AWS API Gateway with Step Function. I have read this tutorial Creating a Step Functions API Using API Gateway but that tutorial needs me to send request in format of
{
"input": "{}",
"name": "PostmanExecution",
"stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:Custom"
}
I want to send normal request and configure this stateMachineArn in API Gateway only, so that clients dont need to send this.
Create your API Gateway resource and method. Then in the "Method Execution" settings, in the Integration Request, use these settings:
- Integration type: AWS Service
- AWS Region: your region
- AWS Service: Step Functions
- AWS Subdomain: your subdomain if you have one - I left it blank
- HTTP method: POST
- Action: StartExecution
- Execution role: needs to be a role with StepFunction start execute policy, such as arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess
- Credentials cache: I left this as default
- Content Handling: Passthrough
Then the magic. Futher down, under Body Mapping Templates:
- Request body passthrough: Never
- Add mapping template : application/json
Futher down in the template text box:
#set($input = $input.json('$'))
{
"input": "$util.escapeJavaScript($input)",
"stateMachineArn": "arn:aws:states:eu-west-1:123456789012:stateMachine:yourStepFunctionName"
}
This will pass the json payload posted to API Gateway through to the Step Function.
Omit the execution name so that each call to API Gateway creates a new execution.
Instead of directly exposing your step function via API Gateway by choosing API Gateway Integration Type "AWS Service", create a Lambda function that calls your Step Function and expose that Lambda function via API Gateway using Integration Type "Lambda". Then you can configure your API Gateway and Lambda function to accept whatever input format that you desire and you could hard-code the stateMacheArn value in your Lambda function or set it as a Lambda environment variable, so that the API Gateway consumer doesn't need to know anything about the ARN.
来源:https://stackoverflow.com/questions/44605228/aws-api-gateway-with-step-function