'Getting authorizer context from Step Function executed from API Gateway

I'm trying to get my API Gateway api to:

  1. Run an authorizer
  2. Pass authorizer context to a Step Function execution
  3. Respond to client with Step Function output

I already have #1 and #3 done, but passing the response of the attached authorizer lambda to the step function is proving to be impossible.

I found this page and this page with reference sheets on what interpolation values you can use for your parameter mapping (Create Integration -> Step Function: StartSyncExecution -> Advanced Settings -> Input) but any time I try to use anything related to $context like $context.authorizer.email, API Gateway just responds with an HTTP 400 and gives me this CloudWatch output:

"Unable to resolve property Input from source {\"lambdaName\": \"arn:aws:lambda:us-east-1:xxxxxxx\", \"reqBody\": $request.body.Input, \"authContext\": $context.apiId }. Please make sure that the request to API Gateway contains all the necessary fields specified in request parameters."

These are the JSON objects I've tried using for the Input text box and all of them either give me an errors when trying to save or throw an HTTP 400 and log the above errors when I visit the route:

  • {"lambdaName": "xxx", "reqBody": $request.body.Input, "authContext": $context.authorizer.email }
  • {"lambdaName": "xxx", "reqBody": $request.body.Input, "authContext": "$context.authorizer.email" }
  • {"lambdaName": "xxx", "reqBody": $request.body.Input, "authContext": $context.apiId }
  • {"lambdaName": "xxx", "reqBody": $request.body.Input, "authContext": $context }
  • {"lambdaName": "xxx", "reqBody": $request.body.Input, "authContext": $event.requestContext.authorizer.email }

It seems like the only way to have authorization code to work with step functions is to wrap my step function called by API Gateway in another step function that authorizes the request and then invokes the endpoint step function. I've researched this for hours and I'm not getting anywhere. Any help at all is appreciated.



Solution 1:[1]

I ended up solving this by using API Gateway v1 and a REST API instead of a HTTP API. For some reason v2's input field currently doesn't work for anything other than $request.body.Input. From there, I hooked up all of my endpoints to a step function that runs the authorization lambda on their Authorization header in the request.

I have a step function that allows me to chain together step function and lambda actions so for most requests I just chain together the authorizer lambda and the endpoint's action (can be lambda or another step function).

The main takeaway here is that if you're using API Gateway and Step Functions, it looks like passing custom-formatted input into your step function isn't very easy to do without using the v1 of API Gateway in a REST API, not an HTTP api. Hopefully this will be fixed in the future.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1