Giter VIP home page Giter VIP logo

dieproduktmacher / serverless-env-generator Goto Github PK

View Code? Open in Web Editor NEW
31.0 5.0 11.0 1.3 MB

A Serverless 1.x plugin to manage environment variables with YAML and turn them into a .env file on deployment. Supports encryption with KMS, multiple stages and custom profiles.

License: MIT License

JavaScript 100.00%
serverless-plugin environment-variables credentials encryption aws aws-kms

serverless-env-generator's Issues

.env being removed after being generated

running

> sls env generate

first creates and then removes just generated .env. Sample output:

Serverless: DOTENV: Could not find .env file.
Serverless: Creating .env file...
Serverless: Removed .env file

same happens for sls package and other commands which seems to be expected according to after:deploy hooks, but shouldn't happen for a manual generation?

Running serverless v1.51.0

TypeError: Cannot convert undefined or null to object

Hi,

I'm currently trying to use serverless-env-generator but must be doing something wrong, as I'm running into this error

TypeError: Cannot convert undefined or null to object
    at Function.assign (<anonymous>)
    at helper.getEnvVars.then.envFiles (/Users/frix00/Sites/betility/betility-graphql/node_modules/serverless-env-generator/src/index.js:120:41)
From previous event:
    at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:464:22)
    at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:496:17)
    at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:116:33)
    at runCallback (timers.js:693:18)
    at tryOnImmediate (timers.js:664:5)
    at processImmediate (timers.js:646:5)
    at process.topLevelDomainCallback (domain.js:121:23)
From previous event:
    at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:103:74)
    at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:28)
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16
    at /usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10
    at FSReqWrap.oncomplete (fs.js:139:20)
From previous event:
    at initializeErrorReporter.then (/usr/local/lib/node_modules/serverless/bin/serverless.js:52:6)
    at runCallback (timers.js:693:18)
    at tryOnImmediate (timers.js:664:5)
    at processImmediate (timers.js:646:5)
    at process.topLevelDomainCallback (domain.js:121:23)
From previous event:
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless.js:38:39)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

Apparently, the culprit is here:
this.options.environment = Object.assign(this.serverless.service.provider.environment, environment, dotenv.config({ path: path.join(config.servicePath, '.env.local') }).parsed)

and this.serverless.service.provider.environment is undefined...


Here my package.json:

{
  "name": "betility-graphql",
  "version": "1.2.0",
  "description": "Grpah QL Layer for Betility",
  "main": "graphql.js",
  "lint-staged": {
    "*.{json,css,md}": [
      "prettier --write",
      "git add"
    ],
    "*.js": [
      "prettier --write",
      "eslint --fix",
      "git add"
    ]
  },
  "scripts": {
    "precommit": "lint-staged",
    "lint": "eslint .",
    "startcache": "serverless offline start --skipCacheInvalidation",
    "start": "serverless offline start",
    "pretest": "npm run lint",
    "test": "jest --coverage",
    "test:watch": "npm test -- --watch"
  },
  "repository": {
    "type": "git",
    "url": "git+ssh://[email protected]:ccinvest/betility-graphql.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "homepage": "https://bitbucket.org/monamourdecomptable/backend-guideline#readme",
  "dependencies": {
    "apollo-server-lambda": "^2.8.1",
    "axios": "^0.19.0",
    "dotenv": "^8.0.0",
    "graphql": "^14.4.2"
  },
  "devDependencies": {
    "aws-sdk": "^2.454.0",
    "eslint": "^5.5.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^3.0.1",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jest": "^21.21.0",
    "eslint-plugin-prettier": "^2.6.2",
    "husky": "^0.14.3",
    "jest": "^23.5.0",
    "lint-staged": "^7.2.2",
    "prettier": "^1.14.2",
    "serverless": "^1.30.1",
    "serverless-domain-manager": "^3.2.6",
    "serverless-env-generator": "^1.4.1",
    "serverless-offline": "^5.9.0",
    "serverless-plugin-warmup": "^4.7.0-rc.1"
  }
}

I currently have a .env :
USER_BACKEND_DOMAIN=http://

and my environment.yml :
dev:
USER_BACKEND_DOMAIN: 'http:///'

After intialising the project, I run
sls env --attribute USER_BACKEND_DOMAIN --value "http://<IP-address>/" --stage dev
Then:
sls env create

Then I create my .env again (since it gets deleted by the "create" command

Finally, I run
sls offline start

and get the error mentioned. I also tried sls offline start --stage dev but I get the same output.

Where am I going wrong ?

Thanks

Not compatible with latest version of serverless (1.60.5)

What did you do?
sls env -a abc -v abc

What happened?
Serverless Error ---------------------------------------

"abc" is not a valid sub command. Run "serverless env" to see a more helpful error message for this command.
What should've happened?
An environment.yml file should have been generated with a variable 'abc' of value 'abc'.

What's the content of your serverless.yml file?

service: test

provider:
name: aws
runtime: nodejs12.x

functions:
hello:
handler: handler.hello
What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.