serverless-google-cloudfunctions icon indicating copy to clipboard operation
serverless-google-cloudfunctions copied to clipboard

Environment Variables need to force Strings

Open pickypg opened this issue 7 years ago • 1 comments

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"

pickypg avatar Oct 23 '18 15:10 pickypg

Updated the documentation as part of PR #6854 to limit the scope of the issue.

gretro avatar Oct 18 '19 04:10 gretro