0

We got a requirement in AWS Api Gateway, that if we receive request with header (authorization) key exist in it, it should call one API and if authorization key ( key only not about keyValue) does not exist in header block it should call another API.

Flow I am visioning is - Apigateway -> (stepfunction/lambda) -> lambda

  • For this I thought of using step functions but I am not sure how to pass total header block as input along with request from API Gateway to step function ?
  • Any best solution to handle this scenarios. (evaluate key exist or not in header block)
  • If step functions wont work ,I believe same issue goes with lambda usage as well, that how to pass total header block as input to lambda.

Really appreciate on any advise.

sarath VNV
  • 15
  • 4

2 Answers2

1

The following body mapping template loops through all the headers and if there is a header for Authorization, it will pass it down to the Lambda/Step Function. You can update it to pass along whatever you require.

{
    "headers": {
        #foreach($param in $input.params().header.keySet())
            #if( $param == 'Authorization' )
                 "$param": "$util.escapeJavaScript($input.params().header.get($param))"
            #end
        #if($foreach.hasNext),#end
        #end
    }
}

Then you should be able to pick this up as a variable in your Step Function and base the next step through a Choice (see https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html#amazon-states-language-choice-state-rules).

NB - I haven't tested this with Step Functions, but from the docs I read, it should work.

K Mo
  • 2,125
  • 8
  • 16
0

if I understand your question correct. You want to pass info to step function from API gateway. then you can make something like this

{
   "input": "{ \"id\": \"$input.params('id')\", \"user_id\": \"$input.path('$').user_id\" }",
   "stateMachineArn": "arn-of-your-state-machine"
}
Mohammed Hassan
  • 1,589
  • 1
  • 8
  • 6