Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

amazon web services - With AWS API Gateway and Lambda, i'm seeing the paths all prefixed with $default

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

question from:https://stackoverflow.com/questions/66055623/with-aws-api-gateway-and-lambda-im-seeing-the-paths-all-prefixed-with-default

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

or we can add stages after it is created.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...