0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lambdaローカル開発にてdotenvにて.envファイルが読み込めない問題と対処

Posted at

備忘録

あくまで備忘録。

問題

Lambdaをローカルで開発時、dotenvを読みこない不具合に陥った。
設定した環境変数が、undifinedになる。

原因を究明した方法

console.log(require('dotenv').config())

原因

.envの読み込みを、プロジェクトディレクトリではなく/var/task/.envで読み込みを行っていた。

対処

環境変数をtemplate.yaml経由で設定する。
*template.yamlの記述省略
config.jsonにはKey:Valに書き込む

sam local invoke -d 5858 -e events/event.json --parameter-overrides $(jq -r 'to_entries[] | "\(.key)=\(.value)"' config.json) Hellworld
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?