Search code examples
serverless-frameworkserverless

In serverless(aws), how to get variable reference from serverless.yml file?


In Serverless.yml, I defined resource:

provider:
  name: aws
  runtime: nodejs6.10
  region: us-east-1
  stage: dev
  environment:
    customerDef: myvariable
resources:
  Resources:
    NewResource:
     Type: AWS::S3::Bucket
     Properties:
      BucketName: ${self:service.name}-${self:provider.stage}-uploads

while in handler.js file which is write handle function.

How to get the reference of BucketName?

How to get the Bucket URI?

How to get the customerDef variable value? (provider->environment->customerDef)


Solution

  • All the environment variables defined under the environment node are available at any .js file using process.env.<variable_name>.

    In your case, to access the customerDef variable you should use process.env.customerDef.

    You can do the same with the BucketName and Bucket URI.