mealesbia
mealesbia

Reputation: 945

How to generate an event with SAM local generate event with queryparameters?

I can generate an event like this in SAM

sam local generate-event apigateway aws-proxy --method GET --path document --body "{"test": "1", "tests2": "2"}" > local-event.json

But this does not really help me because I do not send a body to my endpoint but I send queryparameters like this:

localhost:3000/path?test=1&test2=2

How can I generate an event with query string parameters in SAM for local testing instead of using curl/testing against the local api gateway.

Upvotes: 4

Views: 5429

Answers (1)

visevo
visevo

Reputation: 861

To send query string parameters using sam local invoke:

  1. Generate your event: sam local generate-event apigateway aws-proxy --method GET > local-event.json
  2. In the generated file local-event.json, there should be an object key called "queryStringParameters". Simply add "key": "value" pairs to this object. Save.
  3. Run sam local invoke -e local-event.json

Source: https://seanjziegler.com/how-to-build-an-api-with-aws-lambda-and-api-gateway-using-aws-sam/#5-testing-the-api-with-sam-local-

Upvotes: 11

Related Questions