serverless/serverless-google-cloudfunctions

Environment Variables need to force Strings

Open

#128 opened on Oct 23, 2018

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (124 forks)auto 404
help wanted

Repository metrics

Stars
 (275 stars)
PR merge metrics
 (PR metrics pending)

Description

After updating to 2.1.0 for environment variable support, I ran into an unexpected issue where an environment variable, which is an integer, was rejected by GCF and thus prevented deployment of my function because it wasn't passed to GCF as a string.

{
  "ResourceType": "cloudfunctions.v1beta2.function",
  "ResourceErrorCode": "400",
  "ResourceErrorMessage": {
    "code": 400,
    "message": "Invalid value at 'function.environment_variables[0].value' (TYPE_STRING), 10",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "function.environment_variables[0].value",
            "description": "Invalid value at 'function.environment_variables[0].value' (TYPE_STRING), 10"
          }
        ]
      }
    ],
    "statusMessage": "Bad Request",
    "requestPath": "...",
    "httpMethod": "PUT"
  }
}

The code that _.merge's environment variables should probably call .toString on everything.

Workaround

Simply force the environment variable in your YAML to be a string by wrapping it with quotes.

    environment:
      VARIABLE: "10"

Contributor guide