Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

WSGIApp not working with Serverless Deployment instructions #257

Closed
dgonzo opened this issue Aug 26, 2017 · 2 comments
Closed

WSGIApp not working with Serverless Deployment instructions #257

dgonzo opened this issue Aug 26, 2017 · 2 comments

Comments

@dgonzo
Copy link

dgonzo commented Aug 26, 2017

Using current master (v0.2) of Apistar I am unable to duplicate serverless deploy instructions in the readme.

For further context, you can reference a thread on Apistar's discuss forum here.

You can see my project files in this gist.

What I tried

  1. apistart new . --framework wsgi
  2. confirm the app instance is a wsgi instance by serving with gunicorn: gunicorn app:app --bind:0.0.0.0:5000
  3. zappa init (I have an IAM user that is working for other lambda deployments using zappa that I'm using here -- permissions are confirmed to be working as expected)
    1. Set staging: dev
    2. Set profile/IAM user to user with appropriate permissions: zappadeploy
    3. S3 bucket: default recommended
    4. Where is app's function?: app.app
  4. zappa deploy dev

Everything deploys as expected:

(.venv) gonzo:tz gonzo$ zappa deploy dev
Calling deploy for stage dev..
Downloading and installing dependencies..
Packaging project as zip.
Uploading tz-dev-1503759323.zip (7.4MiB)..
100%|██████████████████████████████████████████████████████████████████████████| 7.75M/7.75M [00:01<00:00, 4.85MB/s]
Scheduling..
Scheduled tz-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading tz-dev-template-1503759338.json (1.5KiB)..
100%|██████████████████████████████████████████████████████████████████████████| 1.58K/1.58K [00:00<00:00, 4.07KB/s]
Waiting for stack tz-dev to create (this can take a bit)..
 75%|████████████████████████████████████████████████████████████                    | 3/4 [00:09<00:05,  5.04s/res]
Deploying API Gateway..
Deployment complete!: https://79st39r9fe.execute-api.us-east-1.amazonaws.com/dev

Running locally with gunicorn all works as expected

gunicorn app:app --bind=0.0.0.0:8080

(.venv) gonzo:tz gonzo$ http :8080
HTTP/1.1 200 OK
Connection: close
Date: Sat, 26 Aug 2017 15:04:02 GMT
Server: gunicorn/19.7.1
Transfer-Encoding: chunked
content-type: application/json

{
    "message": "Welcome to API Star!"
}

Note: I'm using gunicorn to verify that a wsgi app is being used.

Resulting error: 404 not found

(.venv) gonzo:tz gonzo$ http https://79st39r9fe.execute-api.us-east-1.amazonaws.com/dev/
HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Length: 24
Content-Type: application/json
Date: Sat, 26 Aug 2017 15:01:19 GMT
Via: 1.1 d03e57da6d2a774444e63ebbe2e7e9c0.cloudfront.net (CloudFront)
X-Amz-Cf-Id: 48RqKE3t4-TbjTMoc1GBA6tr80b5LlpZgD05JDnSzBrC9PIQt9gjhA==
X-Amzn-Trace-Id: sampled=0;root=1-59a18d3f-93f2ef7ea58b60b90ae0a6f3
X-Cache: Error from cloudfront
x-amzn-RequestId: 6a901662-8a6f-11e7-97a8-9bdd7d92da16

{
    "message": "Not found"
}
@pringlewood
Copy link
Contributor

The issue seems to be with:

https://github.com/encode/apistar/blob/master/apistar/frameworks/wsgi.py#L102

When environ['SCRIPT_NAME'] is removed and the path is just PATH_INFO it works fine when deployed to lambda. @tomchristie I am happy to submit a PR to fix this, but maybe I am missing why it has been done this way?

@tomchristie
Copy link
Member

@pringlewood Good catch yup! The code is wrong exactly as you describe. PR would be ace. Release likely Tuesday.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants