Reputation: 40641
I'm using AWS API Gateway and Lambda
Configuration is as follows:
API Gateway: Protocol is HTTP, route is '$default', integration is to my lambda function, payload format is 1.0, and permissions are correctly configured, stage name is $default. Everything else is vanilla.
Lambda: Runtime is 'custom runtime' (not linux 2), with an executable called 'bootstrap'. It's actually written in Rust using Rocket + rocket_lamb but that shouldn't make much difference.
What i'm finding is that when you browse to the API Gateway Invoke URL, the lambda is called with path = '$default/' instead of '/' - eg it literally includes '$default'.
Am i missing something here? Where is this $default coming from? I thought using '$default' in the route was the wildcard?
Thanks
Upvotes: 1
Views: 2098
Reputation: 40641
So I think i have resolved this... i created a very simply nodejs lambda with the following code and changed my api gateway to point to it:
exports.handler = async (event) => {
const response = {
statusCode: 200,
body: JSON.stringify(event),
};
return response;
};
And from this, I was able to inspect what API gateway was actually passing to the lambda. And from what i can see, it isn't sending $default in any paths. So my conclusion is that rocket_lamb (or rocket) is concatenating fields that it shouldn't be, unfortunately coming up with URLs that look like $default/foo/bar
. Apologies for the wild goose chase all.
Upvotes: 0
Reputation: 10333
Stages help keep different versions of api active, typically used to maintain multiple environments. we can have stages like dev, qa, prod, etc.
Any changes we make to API will not be effective until we deploy to a particular stage.(unless auto-deploy is enabled)
Finally the route will be
https://${apidId}.execute-api.us-east-1.amazonaws.com/${stage}/${route}
Example 1: For /staff route, $default stage , abcdefgh api
https://abcdefgh.execute-api.us-east-1.amazonaws.com/staff
Example 2: for /staff route, dev stage , abcdefgh api
https://abcdefgh.execute-api.us-east-1.amazonaws.com/dev/staff
Example 3: for / route, $default stage , abcdefgh api
https://abcdefgh.execute-api.us-east-1.amazonaws.com/
So, the $default path you are using in lambda function is because you are using $default stage.
For HTTP Api ,
When defining a new api, we can set the stage, which by default is $default
or we can add stages after it is created.
Upvotes: 1