Skip to content

Can't use default value if environment variable does not found. #6685

Closed

Description

@anuj9196

I'm using bitbucket-pipeline to configure CI/CD.

I have the following configuration in the serverless.yml file

provider:
  name: aws
  runtime: nodejs10.x
  region: ${opt:region, ${env:AWS_REGION, 'ap-south-1'}}
  memorySize: ${opt:memory, ${env:MEMORY_SIZE, 512}}tracing:
  apiGateway: ${env:TRACING_API_GATEWAY, true}

I want to be able to pass the variables from the CLI as well as environment variables.

I have set up environment variable for AWS_REGION in the bitbucket pipeline variables but not for MEMORY_SIZE as want to use the default value.

But this gives error while running the pipeline.

Serverless Warning --------------------------------------
 
  A valid option to satisfy the declaration 'opt:region,ap-south-1' could not be found.

Serverless Warning --------------------------------------
 
  A valid environment variable to satisfy the declaration 'env:MEMORY_SIZE,512' could not be found.


Serverless Warning --------------------------------------
 
  A valid environment variable to satisfy the declaration 'env:TRACING_API_GATEWAY,true' could not be found.

Additional Data

  • Serverless Framework Version you're using: 1.52.0
  • Operating System: linux
  • Node Version: 10.15.3 and 11
  • Plugin Version: 2.0.0

Activity

  1. anuj9196 commented on Sep 14, 2019

    @anuj9196
    Author

    Got is solved by defining a custom variable

    custom:
      variables:
         region: ${env:AWS_REGION, 'ap-south-1'}
         memorySize: ${env:MEMORY_SIZE, '512'}
         apiGateway: ${env:TRACING_API_GATEWAY, 'true'}
    

    and use it in the provider

    provider:
      region: ${opt:region, self:custom.variables.region}
      memorySize: ${opt:memory, self:custom.variables.memorySize}
    

    and it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions