Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Forbidden message #2113

Open pexpert opened 4 years ago

pexpert commented 4 years ago

Context

After successfully deploying my Flask application, I am having trouble accessing it. When I make a request using Postman, for example, I receive "Forbidden" as a message.

Expected Behavior

After finishing the deployment, I received a link for my app and tried accessing the routes I programmed in Flask. I expected that passing it through Postman, and adding the api_key as authentication, I would be able to access my API.

Actual Behavior

Instead, I am getting "Forbidden" as a return for my call.

Possible Fix

After making some diggings here, I suspected that using the api_key function could be the problem. Someone suggested that I should change the configuration in AWS Gateway API > Custom Domain Names but there are no API registered there, which raised some warnings in my head. Maybe there is a problem in my permission of AWS that is not allowing it to create the project on Gateway API? I don't know.

After suspecting that the api_key_required camp could be the problem, I removed it. But instead, I got another error: "TypeError: 'NoneType' object is not callable. Now I am even more lost.

Steps to Reproduce

  1. zappa init
  2. zappa deploy dev

Your Environment

{
    "dev": {
        "app_function": "app.app",
        "profile_name": "default",
        "project_name": "default",
        "runtime": "python3.7",
        "s3_bucket": "XXXXX",
        "aws_region": "sa-east-1",
        "slim_handler": true,
        "api_key_required": true

    }
}
jneves commented 4 years ago

As you're not using a domain name, have you added /dev to the beginning of the path of your urls?

pexpert commented 4 years ago

As you're not using a domain name, have you added /dev to the beginning of the path of your urls?

Thanks for your reply.

My path is something like that:

https://XXX.execute-api.sa-east-1.amazonaws.com/dev/search

As you can see, search is the route of my Flask application.

jneves commented 4 years ago

How are you passing the API key to API gateway?

jneves commented 4 years ago

Simpler question: does it work without api_key_required?

pexpert commented 4 years ago

Actually, no. I described what happens when I remove the API key:

After suspecting that the api_key_required camp could be the problem, I removed it. But instead, I got another error: "TypeError: 'NoneType' object is not callable. Now I am even more lost.

jneves commented 4 years ago

Do you have an app.py file on the same directory you have zappa_settings.json and does that file app.py define a WSGI app in the variable app? If not, your function_name needs to be changed.

Jflick58 commented 4 years ago

@pexpert look at your cloud watch logs for the lambda function Zappa creates. This NoneType error can occur after another error. In my case, I was causing an OSError, but because of the way the error handling works, I was seeing the NoneType error in my browser.

lavfilip commented 3 years ago

Getting a 403 with api_key_required set to both false & true