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?
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.
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.
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.
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
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 pathevent.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With