question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to load .env file and set event for `amplify function invoke`

See original GitHub issue

Is 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:

  1. 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

  2. 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 setting amplify/backend/functions/myfuncname/src/event.json to be that content, which ends up getting committed into code too.

  3. 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 - uses dotenv to 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:closed
  • Created 5 years ago
  • Reactions:27
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
yonatanganotcommented, Jan 2, 2020

Any news with this matter?

1reaction
waltermvpcommented, Feb 27, 2020

@gaochenyue can you elaborate?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure environment variables and secrets for your ...
1. Setup a new React app with an Amplify backend · 2. Add a new Lambda function · 3. Use configured environment variable...
Read more >
Functions - Environment variables - AWS Amplify Docs
To configure environment variables for an existing function, run amplify update function , and select Environment variables configuration . You can then add, ......
Read more >
Using Environment Variables
To set a a runtime environment variable using the Google Cloud CLI, use the --set-env-vars flag at deploy time: gcloud functions deploy. FUNCTION_NAME...
Read more >
Deploying and Consuming Serverless Functions with AWS ...
The Amplify Framework offers an easy way to get up and running with serverless functions. The Amplify CLI allows you to create, update, ......
Read more >
Serverless Contact Form Using AWS Amplify
This project makes use of lambda environment variables. The ability to do this via the CLI was introduced in version 5.1.0 . You...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found