sam generate-event - How to set isBase64 to false?

0

Hope you are doing well!

I have been learning a bit on AWS and trying to test lambda locally. Currently I am trying to test the lambda by generating an event as if it comes from the API gateway.

I am using the following command after building my lambda application.

sam local generate-event apigateway aws-proxy --path retrievestatus --**body {"email":"abc@gmail.com"} **| sam local invoke -e - App

The event gets generated and the lambda is invoked. However I have a small issue here. The event generated has the following -

{ "body": "e2VtYWlsOmJ1bHVzdXNhc2hhbmtAZ21haWwuY29tfQ==", "resource": "/{proxy+}", "path": "/retrievestatus", "httpMethod": "POST", "isBase64Encoded": true,

My lambda is not really expecting a base64 encoded string. So I am looking for any suggestions to turn isBase64Encoded to false when I use SAM locally.

I have tried to check the options supported by running - "sam local generate-event apigateway aws-proxy -h" and couldn't find anything to turn it off.

Appreciate any help here.

1개 답변
1
수락된 답변

Based on the code in github, the event is always generated with base64 encoding. What I would suggest is to create the event once and modify it manually. Then use the saved event when you invoke the function using the -e parameter in sam local invoke.

profile pictureAWS
전문가
Uri
답변함 2년 전
  • Thank you for confirmation!

    I have done it as per your suggestion and it works as expected.

    I have generated a local event and stored it in a file sam local generate-event apigateway aws-proxy --path retrievestatus --body {"email":"abc@gmail.com"} > test.json

    Made modifications in test.json to set the isbase64 flag to false and body as per my requirement.

    Then I used sam local invoke to accept the saved event sam local invoke -e test.json

    Thanks again and have a great day!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠