iparips
iparips

Reputation: 23

AWS API Gateway: How to combine multiple Method Request params into a single Integration Request param

I'd like to use API Gateway as a proxy to S3. The bucket is keyed by a composite key made up of two parts like this: [userId]-[documentId].

UserId comes to API Gateway as a path parameter, documentId comes in as a request parameter, for example: [gateway-url]/user1?documentId=doc1

How can I combine the two so that the s3 lookup URL has the following format: https://[bucket-url]/user1-doc1?

Thank you.

Upvotes: 2

Views: 2593

Answers (1)

Ritisha - AWS
Ritisha - AWS

Reputation: 387

  1. Setup your Method Request to accept the path param {userid} and query param {docid}.
  2. Setup your Integration Request to accept both method.request.querystring.docid and method.request.path.userid as URL path params.
  3. Finally, setup your integration endpoint URL as https://your-url/{userid}-{docid}.

A swagger snippet for this is as follows-

"paths": {
"/concat-params/{userid}": {
  "get": {
    "parameters": [
      {
        "name": "userid",
        "in": "path",
        "required": true,
        "type": "string"
      },
      {
        "name": "docid",
        "in": "query",
        "required": false,
        "type": "string"
      }
    ],
    "responses": {...},
    "x-amazon-apigateway-integration": {
      "responses": {...},
      "requestParameters": {
        "integration.request.path.userid":"method.request.path.userid",
    "integration.request.path.docid":"method.request.querystring.docid"
      },
      "uri": "https:.../{userid}-{docid}",
      ...
    }
  }
}

Hope this helps, Ritisha.

Upvotes: 3

Related Questions