4

I'm using serverless framework and 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.
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285

1 Answers1

-1

First, those are warnings not errors. A Serverless error would be something like:

Serverless Error ---------------------------------------

Trying to populate non string value into a string for variable ${opt:stage}. Please make sure the value of the property is a string.

This specific error happens because in the custom tag I've declared: var: ${opt:stage}-something which should be changed like:

provider:
  stage: ${opt:stage, 'local'}

custom:
  var: ${self:provider.stage}-something

I think in your case, you need to update region like this:

region: ${opt:region, env:AWS_REGION, 'ap-south-1'}

I couldn't reproduce the last warning though but I reckon ENV variables should be defined in bitbucket-pipelines.yml (or similar CI pipeline YAML) under args or variables and then they can be accessed using ${env:VAR}.

pamit
  • 326
  • 2
  • 10