title: Accessing environment configs defined in serverless.yaml in standalone nodejs script
body: <p>I have recently started working on a project in which we are using serverless framework. We are using docker to make dev environment easier to setup.</p>
  <p>As part of this docker setup we have created a script that creates S3 buckets &amp; tables among other things. We were earlier defining environment variables in the <code>docker-compose</code> file and were accessing them in our nodejs app. For purposes of deployment to other environments our devops team defined a few environment variables in the <code>serverless.yaml</code> file resulting in environment configs being present at two places. We are now planning to move all the environment configs defined in our <code>docker-compose</code> file to <code>serverless.yaml</code>. This works well for our lambdas functions as they are able to read these configs, but it doesn't work for the standalone setup script that we have written.</p>
  <p>I tried using <a href="https://www.serverless.com/plugins/serverless-scriptable-plugin" rel="nofollow noreferrer">this</a> plugin(<code>serverless-scriptable-plugin</code>) in an attempt to be able to read these env variables but still unable to do so.</p>
  <p>Here is my <code>serverless.yaml</code> file</p>
  <pre><code>service:
    name: my-service
  
  frameworkVersion: '2'
  configValidationMode: error
  
  provider:
    name: aws
    runtime: nodejs14.x
    region: 'us-east-1'
    profile: ${env:PROFILE, 'dev'}
    stackName: stack-${self:provider.profile}
    apiName: ${self:custom.environment_prefix}-${self:service.name}-my-api
    environment: ${self:custom.environment_variables.${self:provider.profile}}
  
  plugins:
    - serverless-webpack
    - serverless-scriptable-plugin
    - serverless-offline-sqs
    - serverless-offline
  
  functions:
    myMethod:
      handler: handler.myHandler
      name: ${self:custom.environment_prefix}-${self:service.name}-myHandler
      events:
        - sqs:
            arn:
              Fn::GetAtt:
                - MyQueue
                - Arn
  
  resources:
    Resources:
      MyQueue:
        Type: AWS::SQS::Queue
        Properties:
          QueueName: ${self:custom.queuename}
          Tags:
            - Key: product
              Value: common
            - Key: service
              Value: common
            - Key: function
              Value: ${self:service.name}
            - Key: region
              Value: ${env:REGION}
  
  package:
    individually: true
  
  custom:
    webpack:
      webpackConfig: ./webpack.config.js
      includeModules: true
    serverless-offline:
      host: 0.0.0.0
      port: 3000
  
    serverless-offline-sqs:
      apiVersion: '2012-11-05'
      endpoint: http://sqs:9324
      region: ${self:provider.region}
      accessKeyId: root
      secretAccessKey: root
      skipCacheInvalidation: false
  
    localstack:
      stages:
        - local
      lambda:
        mountCode: true
      debug: true
  
    environment_prefixes:
      staging: staging
      production: production
      dev: dev
    environment_prefix: ${self:custom.environment_prefixes.${self:provider.profile}}
    queuename: 'myQueue'
  
    environment_variables:
      dev:
        AWS_ACCESS_KEY_ID: test
        AWS_SECRET_ACCESS_KEY: test
        BUCKET_NAME: my-bucket
        S3_URL: http://localstack:4566
        SLS_DEBUG: '*'
  
    scriptable:
      commands:
        setup: node /app/dockerEntrypoint.js
  </code></pre>
  <p>In my DockerFile I try executing script using <code>sls setup</code> CMD. I initially thought using <code>sls</code> command might expose these environment variables defined in <code>serverless.yaml</code> file but it doesn't seem to happen.</p>
  <p>Is there any other way this can be achieved? I am trying to access these variables using <code>process.env</code> which works for lambdas but not for my standalone script. Thanks!</p>