How to make Lambda + API Gateway obey REQUEST_URI?

0

I created an AWS Lambda with my application (a Web server) written in Rust Actix. I use https://crates.io/crates/lambda-web

Then I added this Lambda as the backend of an AWS HTTP API. The HTTP API has only $default stage.

https://XXX.execute-api.us-east-1.amazonaws.com/ produces correct result (what my packaged Web server outputs when the root is requested).

But https://XXX.execute-api.us-east-1.amazonaws.com/p/YYY produces: {"message":"Not Found"} what is surely not my Web server's output.

My task is to run the Web server in Lambda with path forwarded to the server in the normal way (as REQUEST_URI). So, when I request https://XXX.execute-api.us-east-1.amazonaws.com/p/YYY it should pass /YYY to my application. How?

Or probably it can be done with Lambda@Edge? Lambda@Edge follows the same protocol for Lambda as AWS HTTP API, doesn't it? In this case, there would be a CloudFront without origins, or what should I put as the origin, an arbitrary domain? Should Lambda@Edge be invoked on request or on response?

1개 답변
0

Look at Proxy integrations. You need to define a greedy path using /{Proxy+}. This way you do not need to specify all routes in the API but rather specify one and let the Lambda function do the routing internally.

As an alternative you could create multiple routes and assign each one to a different function.

profile pictureAWS
전문가
Uri
답변함 2년 전
profile picture
전문가
검토됨 한 달 전
  • After I added ANY /{proxy+} route, every request (including the root request /) returns {"message":"Internal Server Error"}.

    I tried both /{proxy+} and /{Proxy+}.

  • Is your target invoked? If so, maybe it returns a malformed answer.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠