Add ability to load .env file and set event for `amplify function invoke`
See original GitHub issueIs your feature request related to a problem? Please describe.
I want to test out a lambda function locally. I am running into three annoying things:
-
If I need to set environment variables (like if I’m working with Stripe and need to set the secret key or just to set ENV), I have to manually pass those into the call like:
ENV=dev STRIPE_SECRET_KEY=sec_foo amplify function invoke myfuncname -
If I want to specify an event, I have to first come up with a valid event (which I’m getting by logging the event to the console then looking at cloudwatch logs
JSON.stringify(req.apiGateway.event)), and then settingamplify/backend/functions/myfuncname/src/event.jsonto be that content, which ends up getting committed into code too. -
I have to hit enter twice to accept the default script file and handler function
Describe the solution you’d like
I wish I could run the command as such:
amplify function invoke myfuncname --env ../.env --event ./events/myfuncname-get.json -y
In this case:
--env- usesdotenvto set process.env variables for me--event- specifies the event JSON-y- auto accepts the default script and handler function
Describe alternatives you’ve considered
I’ve written my own bash script that does some of this work for me. It also sets AWS_SDK_LOAD_CONFIG=1 and AWS_PROFILE=myprofilename
Additional context
Similarly would love if amplify push accepted a -y argument (I guess I could do yes | amplify push for this one).
Also, I would absolutely love if there was an easy to use event generator to generate valid GET/POST/PUT/DELETE requests (in this case I’m working with lambdas that use API Gateway).
One more thing, why does amplify function invoke myfuncname remain open and listening on a port after it runs? Am I able to do something with it or do I have to just manually kill it each time?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:27
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
Any news with this matter?
@gaochenyue can you elaborate?