I’ve been going in circles for quite a while trying to set-up and access variables from my serverless.yml in node.js
The docs are quite confusing in this respect, which I somewhat understand as you are trying to create a system which is incredibly flexible to the needs of a huge target audience, but some basic examples should help much of the community getting started.
Specifically, I am trying to get a different s3 bucket based on which stage I’m running. I’m not too picky on how this happens (I don’t think), I just want to get it done.
Reading through the docs, trying everything it has again and again, this is where I’m at.
name: aws
runtime: nodejs4.3
stage: ${opt:stage, self:custom.default_stage}
environment:
bucket: ${self:stage}-bucketname
functions:
view:
handler: handler.view
environment:
bucket: ${self:stage}-bucketname
From here, I expected to be able to get process.env.bucket
, but unfortunately in my handler code, bucket is not in my env.
No problem, let’s not do environment, let’s try stageVariable, maybe that’s the correct way. Following this guide here in the forums Make stageVariables clear - #2 by buggy
stage: ${opt:stage, self:custom.default_stage}
environment: ${file(env.yml):${self:provider.stage}}
referenced in an external file env.yml, in the output context.stageVariables=null
Then followed this Using Environment Variables with the Serverless Framework
Again, nothing in environment variables. Are any of these supposed to work???