0

I have a Lambda that takes a list of skus,

{ "skus" : [
    "sku1", 
    "sku2"
    ] 
}

I want to invoke it from HTTP requests to either

/inventory/sku1,sku2 

or

/inventory?sku=sku1&sku=sku2

How can I achieve that mapping in API Gateway?

4
  • Look at example here docs.aws.amazon.com/apigateway/latest/developerguide/… under header "Param Mapping Template Example". Commented Jul 14, 2017 at 7:27
  • Thanks, but I don't see any help there parsing /inventory/sku1,sku2 into a list to iterate over, and, at least in the Method Test UI, I don't seem to be able to repeat a query string parameter Commented Jul 14, 2017 at 7:46
  • Is it ok for you to make a GET request like /?skus=[1,2,3,4] ? In this case you can just map one param. Commented Jul 14, 2017 at 8:32
  • That doesn't look ideal, but I think I have discovered a solution Commented Jul 14, 2017 at 8:46

1 Answer 1

3

You can use String::split for the path-based approach.

#set($skus = $input.params('skus').split(","))
{
  "skus": [ 
     #foreach($sku in $skus)
      "$sku"
     #if($foreach.hasNext),#end
     #end
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.