I have a Lambda setup with a Python handler, which I have created an API endpoint to receive only POST methods. What I can't figure out is how my Lambda should tell the API Gateway that things have successfully completed and return a HTTP 200 status code. Has anyone ventured down this path?
Asked
Active
Viewed 6,619 times
3 Answers
1
In python lambda just do
raise Exception('notfound')
Instead of notfound use any other keyword.
Then in apigateway you need to map 'notfound'
to some response status code. I use swagger for this so here is example how to track 'notfound'
:
"/tags/getById": {
"get": {
"summary": "Find the tag by it's ID",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Tag"
}
},
"404": {
"description": "No tag found"
}
},
"parameters": [xxxxxxx],
"x-amazon-apigateway-integration": {
"requestTemplates": {xxxxx},
"uri": {xxxxxx},
"responses": {
"default": {
"statusCode": "200"
},
"notfound": {
"statusCode": "404"
}
},
"httpMethod": "POST",
"type": "aws"
}
}
}

Ivan Borshchov
- 3,036
- 5
- 40
- 62
0
You should be able to accomplish your goal by using the returning value of your handler. See official AWS Lambda Python Model Handler Types.
You also need API Gateway
properly configured with your Integration Response
. You can find more information about how that's done in the official API Gateway Introductory Blog post, most important is the Integration Response
section.

adamkonrad
- 6,794
- 1
- 34
- 41
0
I wanted other http error codes like 400 & 500 too, so I wrote an answer here. See it for further details:

Sean Long
- 2,163
- 9
- 30
- 49

Manohar Reddy Poreddy
- 25,399
- 9
- 157
- 140