I deployed a Python Post API lambda, using Serverless framework.
Detail of code as below:
app.py
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/process', methods=['POST'])
def process():
content = request.json
print content
return jsonify(content)
if __name__ == "__main__":
app.run()
serverless.yml
service: my-service
plugins:
- serverless-python-requirements
- serverless-wsgi
custom:
wsgi:
app: app.app
packRequirements: false
pythonRequirements:
dockerizePip: false
package:
exclude:
- node_modules/**
- venv/**
provider:
name: aws
runtime: python2.7
stage: dev
region: eu-west-1
functions:
app:
handler: wsgi.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
I configured the SQS to trigger the lambda. I send a SQS Message, the lambda is triggered (I checked it from CloudWatch), but the SQS message is stuck in flight. It seems that SQS cannot be consumed by lambda.
Any suggestion is appreciated
****UPDATE*****
After check the CloudWatch carefully, I found some exceptions
u'headers': KeyError
Traceback (most recent call last):
File "/var/task/wsgi.py", line 100, in handler
return serverless_wsgi.handle_request(wsgi_app, event, context)
File "/var/task/serverless_wsgi.py", line 73, in handle_request
headers = Headers(event[u"headers"])
KeyError: u'headers'
print. Not sure why you wrote this with flask, since it's behind SQS instead of API Gateway. I may be wrong, but this doesn't seem right. - Michael - sqlbot