POST メソッドのみを受け取る API エンドポイントを作成した Python ハンドラーを使用して Lambda をセットアップしました。私が理解できないのは、Lambda が API Gateway に物事が正常に完了し、HTTP 200 ステータス コードを返すことを伝える方法です。この道を進んだ人はいますか?
3986 次
3 に答える
1
Pythonラムダでは、
raise Exception('notfound')
notfound の代わりに、他のキーワードを使用します。
'notfound'
次に、apigateway で、いくつかの応答ステータス コードにマップする必要があります。これにはswaggerを使用するため、追跡方法の例を次に示します'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"
}
}
}
于 2017-01-19T18:56:08.010 に答える
0
ハンドラーの戻り値を使用して、目標を達成できるはずです。公式のAWS Lambda Python モデルのハンドラー タイプを参照してください。
API Gateway
で適切に構成する必要もありますIntegration Response
。それがどのように行われるかについての詳細は、公式のAPI Gateway 入門ブログ投稿で見つけることができます。最も重要なのはIntegration Response
セクションです。
于 2015-10-30T02:05:32.360 に答える
0
400 や 500 などの他の http エラー コードも必要だったので、ここに回答を書きました。詳細については、次を参照してください。
于 2016-12-27T11:43:34.143 に答える