2

Following the documentation, I tried declaring environment variables in the serverless.yml file under provider:

provider:
  cfLogs: true
  name: aws
  runtime: nodejs4.3
  stage: dev
  region: eu-west-1
  profile: serverless-admin
  environmnent:
    IS_REMOTE: ${file(./config.yml):IS_REMOTE}
    REMOTE_ENV: "YES"

None of these are available to me when trying to get them using process.env.IS_REMOTE or process.env.REMOTE_ENV.

This is the log of trying to console.log them:

2017-01-01 06:22:57.777 (+02:00)        undefined       REMOTE_ENV:  undefined
2017-01-01 06:22:57.777 (+02:00)        undefined       IS_REMOTE:  undefined

This is inside Lambda when using serverless invoke (not locally).

Hope someone can help me figure this out, as it seems like I'm following the docs about right.

2 Answers 2

2

From the code, it looks like environmnent is misspelt.

Sign up to request clarification or add additional context in comments.

Comments

1

This feature works fine for me. I believe that you have mistyped something.

Could you please create a new project and test the following steps? Maybe we can find what is your issue through a MCVE. Give me a feedback if this code does not work for you.

  1. Check your Serverless version (expected: 1.4.0)

    serverless --version
    
  2. Create a new project

    serverless create --template aws-nodejs --name test-project
    
  3. Use the following serverless.yml

    service: test-project
    
    provider:
      name: aws
      runtime: nodejs4.3
      environment:
        VAR_1: foo
    
    functions:
      hello:
        handler: handler.hello
    
  4. Use the following handler.js

    module.exports.hello = (event, context, callback) => {
    
      console.log(process.env.VAR_1);
    
      const response = {
        statusCode: 200,
        body: JSON.stringify({
          message: process.env.VAR_1
        }),
      };
    
      callback(null, response);
    };
    
  5. Deploy

    serverless deploy
    
  6. Test

    serverless invoke --function hello
    

HTTP result:

{
    "statusCode": 200,
    "body": "{\"message\":\"foo\"}"
}

Log:

2017-01-02T20:13:58.551Z    fg57ea3c-e127-11e6-bf5a-93b2958503d8    foo

1 Comment

Hmm I actually tried to delete this question as the next day I looked at it with fresh eyes and saw my serverless.yml says environmnent instead of environment. Subtle but deadly. Since for some reason the deletion didn't go through, and you did answer with "mistyped", this is the accepted answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.