REST API sent to API Gateway, how to access POST body data (application/json type) from within lambda application?

0

Placing data in POST body of a rest api request. Looks like below:

{"Email":"testemaillogs@logs.com", "comment": "message one is here" }

So far so good, can use Postman to hit API Gateway, and use lambda functions to do various things like access comprehend API. Now when I need to access this data to write it somewhere (like dynamoDB), I try like this:

def lambda_handler(event, context): email = event["Email"] comment = event["comment"]

Getting a "key error" in cloudwatch logs from this approach like this:

Field Value @ingestionTime 1594168745270 @log 255070150261:/aws/lambda/Feedback @logStream 2020/07/08/$LATEST616634687067483d9e6f07d95fb20b30 @message ERROR KeyError: 'Email' Traceback (most recent call last): File "/var/task/lambda_function.py", line 7, in lambda_handler email = event"Email" @timestamp 1594168736201

In API Gateway I have set up a Model schema like this and required it under Method Execution in the API Gateway resources manager.

{ "type":"object", "properties":{ "Email":{"type":"string"}, "comment":{"type":"string"} }, "title":"Input" }

Anything else to check here?

1回答
0
承認された回答

If you used Lambda Proxy Integration, you get in the event much more details, and the content is under a "body" field. Best would be to print the event object and then you will be able to see exactly where your data is within the event object.

profile pictureAWS
エキスパート
Uri
回答済み 4年前
profile picture
エキスパート
レビュー済み 1ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ