Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm working on an aws serverless project and need to test the lambda functions locally. 

I am using serverless invoke local -f {function_name} command to test the API calls that do not request any path or query parameters. 

My question is how can I use this command to pass any path or query parameter to the function?

Example serverless description

getFoodDetails:

    handler: handler.getFoodDetails

    events:

      - http:

          method: get

          path: /foods/{food_id}

          cors: true

          request:

            parameters:

              paths:

                food_id: true

closed

1 Answer

0 votes
by (44.4k points)
selected by
 
Best answer

Data string

--data option can be used to pass a string data as an event to your Lambda function

serverless invoke local -f {function_name} --data '{ "queryStringParameters": {"id":"P50WXIl6PUlonrSH"}}'

Data file

You can use --path to a JSON file with the data as the event, and in the event file, you can define the data you want.

serverless invoke --function {function_name} --path event_mock.json

If you use both --path and --data, the --path file’s data will overwrite the data you passed with the --data flag.

Browse Categories

...