Having trouble setting environment variables for AWS Lambda using Serverless v1.4.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.
javascript node.js amazon-web-services aws-lambda serverless-framework
add a comment |
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
add a comment |
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
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
javascript node.js amazon-web-services aws-lambda serverless-framework
edited Jan 2 '17 at 20:24
Zanon
14.3k127594
14.3k127594
asked Jan 1 '17 at 4:27
Harel RozentalHarel Rozental
495
495
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
Check your Serverless version (expected: 1.4.0)
serverless --version
Create a new project
serverless create --template aws-nodejs --name test-project
Use the following serverless.yml
service: test-project
provider:
name: aws
runtime: nodejs4.3
environment:
VAR_1: foo
functions:
hello:
handler: handler.hello
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);
};
Deploy
serverless deploy
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
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
add a comment |
From the code, it looks like environmnent is misspelt.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Check your Serverless version (expected: 1.4.0)
serverless --version
Create a new project
serverless create --template aws-nodejs --name test-project
Use the following serverless.yml
service: test-project
provider:
name: aws
runtime: nodejs4.3
environment:
VAR_1: foo
functions:
hello:
handler: handler.hello
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);
};
Deploy
serverless deploy
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
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
add a comment |
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.
Check your Serverless version (expected: 1.4.0)
serverless --version
Create a new project
serverless create --template aws-nodejs --name test-project
Use the following serverless.yml
service: test-project
provider:
name: aws
runtime: nodejs4.3
environment:
VAR_1: foo
functions:
hello:
handler: handler.hello
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);
};
Deploy
serverless deploy
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
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
add a comment |
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.
Check your Serverless version (expected: 1.4.0)
serverless --version
Create a new project
serverless create --template aws-nodejs --name test-project
Use the following serverless.yml
service: test-project
provider:
name: aws
runtime: nodejs4.3
environment:
VAR_1: foo
functions:
hello:
handler: handler.hello
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);
};
Deploy
serverless deploy
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
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.
Check your Serverless version (expected: 1.4.0)
serverless --version
Create a new project
serverless create --template aws-nodejs --name test-project
Use the following serverless.yml
service: test-project
provider:
name: aws
runtime: nodejs4.3
environment:
VAR_1: foo
functions:
hello:
handler: handler.hello
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);
};
Deploy
serverless deploy
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
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
add a comment |
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
add a comment |
From the code, it looks like environmnent is misspelt.
add a comment |
From the code, it looks like environmnent is misspelt.
add a comment |
From the code, it looks like environmnent is misspelt.
From the code, it looks like environmnent is misspelt.
answered Nov 15 '18 at 1:59
GeeDawgGeeDawg
736
736
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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