Having trouble setting environment variables for AWS Lambda using Serverless v1.4.0












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.










share|improve this question





























    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.










    share|improve this question



























      2












      2








      2


      0






      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.










      share|improve this question
















      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.







      javascript node.js amazon-web-services aws-lambda serverless-framework






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 '17 at 20:24









      Zanon

      14.3k127594




      14.3k127594










      asked Jan 1 '17 at 4:27









      Harel RozentalHarel Rozental

      495




      495
























          2 Answers
          2






          active

          oldest

          votes


















          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





          share|improve this answer





















          • 1





            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

            – Harel Rozental
            Jan 3 '17 at 21:28





















          2














          From the code, it looks like environmnent is misspelt.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41413360%2fhaving-trouble-setting-environment-variables-for-aws-lambda-using-serverless-v1%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            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





            share|improve this answer





















            • 1





              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

              – Harel Rozental
              Jan 3 '17 at 21:28


















            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





            share|improve this answer





















            • 1





              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

              – Harel Rozental
              Jan 3 '17 at 21:28
















            1












            1








            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





            share|improve this answer















            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






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 23 '17 at 10:30









            Community

            11




            11










            answered Jan 2 '17 at 20:15









            ZanonZanon

            14.3k127594




            14.3k127594








            • 1





              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

              – Harel Rozental
              Jan 3 '17 at 21:28
















            • 1





              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

              – Harel Rozental
              Jan 3 '17 at 21:28










            1




            1





            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

            – Harel Rozental
            Jan 3 '17 at 21:28







            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

            – Harel Rozental
            Jan 3 '17 at 21:28















            2














            From the code, it looks like environmnent is misspelt.






            share|improve this answer




























              2














              From the code, it looks like environmnent is misspelt.






              share|improve this answer


























                2












                2








                2







                From the code, it looks like environmnent is misspelt.






                share|improve this answer













                From the code, it looks like environmnent is misspelt.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 15 '18 at 1:59









                GeeDawgGeeDawg

                736




                736






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41413360%2fhaving-trouble-setting-environment-variables-for-aws-lambda-using-serverless-v1%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues