Duncan McGregor
Duncan McGregor

Reputation: 18177

How do I map multiple HTTP parameters to a JSON array using AWS API Gateway

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?

Upvotes: 0

Views: 626

Answers (1)

Duncan McGregor
Duncan McGregor

Reputation: 18177

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
  ]
}

Upvotes: 3

Related Questions