Problem
When I run my lambda API locally with sam local start-api, I get the error {"message":"Missing Authentication Token"} for a request that is not supposed to require an authentication token.
Code
In my cloudformation template file I create a lambda function (see below) and an API Gateway for the API calls. As this setup will fail to run locally with start-api (thank you AWS?), I added the Events section you can see below.
MyApi:
Type: AWS::Serverless::Function
Properties:
CodeUri: myapi
Handler: lambda_handler.lambda_handler
Runtime: python3.10
Architectures:
- arm64
...
Events:
Any:
Type: HttpApi
Properties:
Path: '/myapi/*'
Method: any
Steps to reproduce
- I run
sam build && sam local start-apito run the API. - I run
curl localhost:8080/myapi/ping- 8080 is configured in samconfig
/myapi/pingis configure in the API Gateway and the lambda_handler itself.
Problem
I don't understand why, but
Path: '/myapi/*'seems to have been the problem.How to fix
Using
Path: '/{proxy+}'instead, fixed it.Warning: If you use this in your template that you use for deployment, you will have the same setting on your server. This is probably not what you want.
This is a community wiki. Whoever knows more, feel free to add details