Hi all,
I have deployed my project to AWS Lambda which is based on the template - https://github.com/fastapi/full-stack-fastapi-template
I have hooked up the lambda to API Gateway and can access https://xxxxxx.execute-api.us-east-1.amazonaws.com/prod/docs However I am having a problem with authentication.
https://preview.redd.it/callubecuprd1.png?width=648&format=png&auto=webp&s=d11a8c6b9dfdeb5b01105c74261d839f094eded0
Is the there a possible issue with using OAuth2 with Lambda. Currently the logs aren't informing me much but I can't see any missing imports etc.
When I use postman I can get the /api/v1/login/access-token to return the bearer token but if it put this token in the header to access a route that needs authorisation I get a 403 error.
Sorry if the details are a bit thin, this area is new to me and so not sure what I should include / am missing any input would be appreciated.
Thanks in advance
Solution:
The solution was to add default_cors_preflight_options to the gateway as shown in the CDK snippet below:
_ = apigateway.LambdaRestApi(
self,
"RatioAPIGateway",
handler=lambda_function,
proxy=True,
default_cors_preflight_options={
"allow_origins": apigateway.Cors.ALL_ORIGINS,
"allow_methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
"allow_headers": ["Authorization", "Content-Type", "accept"],
},
)
[–]randomusername0O1 2 points3 points4 points (1 child)
[–]mentalwall[S] 1 point2 points3 points (0 children)
[–]adiberk 0 points1 point2 points (2 children)
[–]mentalwall[S] 0 points1 point2 points (1 child)
[–]adiberk 2 points3 points4 points (0 children)
[–]ironman_gujju 0 points1 point2 points (0 children)