Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use wildcards or catch-all paths in AWS API Gateway

I am trying to redirect all traffic for one domain to another. Rather than running a server specifically for this job I was trying to use AWS API Gateway with lambda to perform the redirect.

I have this working ok for the root path "/" but any requests for sub-paths e.g. /a are not handled. Is there a way to define a "catch all" resource or wildcard path handler?

like image 823
David Avatar asked Mar 03 '16 13:03

David


People also ask

What are the three common ways you can interact with the API of AWS?

There are several ways to call this API. They include using the AWS Command Line Interface (AWS CLI), or by using an AWS SDK. In addition, you can enable API creation with AWS CloudFormation templates or (in the case of REST APIs and HTTP APIs) Working with API Gateway extensions to OpenAPI.

How many requests can AWS API gateway handle?

Amazon API Gateway has raised the default limit on requests made to your API to 10,000 requests per second (RPS) from 1,000 RPS. The burst limit has been raised to 5,000 requests across all APIs in your account from the original limit of 2,000 requests.

Which of the following methods does Amazon API gateway support?

Q: What API types are supported by Amazon API Gateway? Amazon API Gateway offers two options to create RESTful APIs, HTTP APIs and REST APIs, as well as an option to create WebSocket APIs.


2 Answers

As of last week, API Gateway now supports what they call “Catch-all Path Variables”.

Full details and a walk-through here: API Gateway Update – New Features Simplify API Development

like image 69
Avi Flax Avatar answered Sep 20 '22 20:09

Avi Flax


You can create a resource with path like /{thepath+}. Plus sign is important.

Then in your lambda function you can access the value with both

  • event.path - always contains the full path
  • or event.pathParameters.thepath - contains the part defined by you. Other possible use case: define resource like /images/{imagepath+} to only match pathes with certain prefix. The variable will contain only the subpath.

You can debug all the values passed to your function with: JSON.stringify(event)

Full documentation

like image 44
geekQ Avatar answered Sep 23 '22 20:09

geekQ