簡體   English   中英

使用 pm2 無法訪問 ElasticBeanstalk 環境變量

[英]ElasticBeanstalk Environment Variables not accessible using pm2

我已經能夠使用如下所示的基本 npm 啟動腳本在 ElasticBeanstalk 上成功運行我的應用程序。

"scripts": {
    "start": "NODE_ENV=production node ./bin/www"
}

在我的服務器上,我現在已經全局安裝了 pm2 並更新了我的package.json中的start腳本以使用 pm2。

"scripts": {
    "start": "pm2 start ./bin/www"
}

pm2 啟動該過程,我可以通過查看我的日志看到這一點,但它似乎無法訪問我為 ElasticBeanstalk 設置的環境變量。 我在文件.ebextensions/options.config中使用aws:elasticbeanstalk:application:environment選項設置環境變量,如下所示。

option_settings:
  aws:elasticbeanstalk:application:environment:
    keyOne: foo
    keyTwo: bar
    keyThree: foo

pm2 抱怨無法讀取環境變量的未定義屬性。

0|www    | TypeError: Cannot read property 'keyOne' of undefined
0|www    |     at Object.<anonymous> (/var/app/current/app.js:26:38)
0|www    |     at Module._compile (internal/modules/cjs/loader.js:999:30)
0|www    |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|www    |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|www    |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|www    |     at Module.require (internal/modules/cjs/loader.js:887:19)
0|www    |     at Module.Hook._require.Module.require (/var/app/current/node_modules/require-in-the-middle/index.js:80:39)
0|www    |     at require (internal/modules/cjs/helpers.js:74:18)
0|www    |     at Object.<anonymous> (/var/app/current/bin/www:7:11)
0|www    |     at Module._compile (internal/modules/cjs/loader.js:999:30)

我需要先獲取文件嗎? 我想避免在 pm2 的生態系統.config.js 文件中設置環境變量,因為我現在還可以使用當前實施的方法從 AWS 控制台以可視方式管理環境變量。

如果您已經創建了 PM2 流程,然后更新了環境變量,您應該刪除 PM2 流程並使用生態系統文件重新創建它。

刪除和創建操作考慮新創建的環境變量,但不考慮重新啟動。 我不知道為什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM