Skip to content

Environment variable must contain string error when pulling from Secrets Manager #5869

Closed

Description

@josephbulger

This is a Bug Report

Description

  • What went wrong?

When utilizing a secret from Secrets Manager in the form of

SomeEnvVar: ${ssm:/aws/reference/secretsmanager//my/env/var/here~true}

whenever I try to run sls deploy with this configuration on version 1.38 it gives me the error

Environment variable EncoderProfiles must contain string

  • What did you expect should have happened?

In serverless version1.36 this would work fine, and the secret would get pulled into my lambda env var without issue.

  • What was the config you used?

SomeEnvVar: ${ssm:/aws/reference/secretsmanager//my/env/var/here~true}

  • What stacktrace or error message from your provider did you see?

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

Environment variable EncoderProfiles must contain string

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com

Your Environment Information -----------------------------
OS: linux
Node Version: 11.2.0
Serverless Version: 1.38.0

Similar or dependent issues:

Additional Data

  • Serverless Framework Version you're using: 1.38 (works on 1.36)

  • Operating System: build agent is alpine

  • Stack Trace:
    Serverless Error ---------------------------------------

    Environment variable EncoderProfiles must contain string

    Get Support --------------------------------------------
    Docs: docs.serverless.com
    Bugs: github.com/serverless/serverless/issues
    Issues: forum.serverless.com

    Your Environment Information -----------------------------
    OS: linux
    Node Version: 11.2.0
    Serverless Version: 1.38.0

  • Provider Error messages:

Environment variable EncoderProfiles must contain string

Activity

  1. dschep commented on Feb 27, 2019

    @dschep
    Contributor

    Is the secret your referencing actually a string or is it a JSON blob? The AWS console pushes you to using JSON blobs (the key/value UI creates JSON & DB secrets are also JSON blobs)
    if it's the later, you'll need to do something like this:

    custom:
      mySecret: ${ssm:/aws/reference/secretsmanager//my/env/var/here~true}
    provider:
      environment:
        SomeEnvVar: ${self:custom.mySecret.THE_NAME_OF_THE_FIELD_IN_THE_JSON_YOU_WANT}

    To check what SomeEnvVar is being set to, run sls print

  2. agbanil commented on Mar 11, 2019

    @agbanil

    Hello @dschep,

    I'm having this same issue. I made a call to the secret manager like this:

    service: someservice
    provider:
      stage: staging
      region: eu-central-1
      name: aws
      runtime: nodejs6.10
    custom:
      variables: ${ssm:/aws/reference/secretsmanager/somesecret~true} <== SSM call
    functions:
      main:
        handler: index.serverlessHandler
        events:
          - http:
              path: v1/somepath
              method: get
    

    I tried to reference a variable the way you mentioned ${self:custom.variables.THE_NAME_OF_THE_FIELD_IN_THE_JSON_YOU_WANT}, but it wasn't working, so I printed and got this:

    provider:
      stage: staging
      region: eu-central-1
      name: aws
      runtime: nodejs6.10
    custom:
      variables: '{"databasehost":"something","databasename":"something"}' <== response from ssm
    functions:
      main:
        handler: index.serverlessHandler
        events:
          - http:
              path: v1/somepath
              method: get
    

    This shows that the response from AWS is in fact a string and not a JSON blob. In my case I was a expecting a JSON since I have multiple variables in the secret manager.

  3. mesaugat commented on Mar 12, 2019

    @mesaugat
    Contributor

    Reverting back to v1.37.0 worked for me. I was getting the same error after upgrading to v1.38.0.

  4. gudata commented on Jul 14, 2019

    @gudata

    in v1.47.0
    it works.

     secrets:
        handler: launcher/functions/secrets.handle
        package:
          exclude:
            - ./**
          include:
            - launcher/functions/secrets.py
            - helpers/**
        environment:
          RDS_SPACE_UTIL_HOST: ${self:custom.rds-space_util.host}
    custom:
      rds-space_util: ${ssm:/aws/reference/secretsmanager/rds-space_util~true}
    

    But! if i use

    custom:
      rds-space_util: ${ssm:aws/reference/secretsmanager/rds-space_util~true}
    

    instead of

    custom:
      rds-space_util: ${ssm:/aws/reference/secretsmanager/rds-space_util~true}
    

    Then I get the json as string, which is expected because the prefix should be /aws and not aws

  5. medikoo commented on Apr 12, 2021

    @medikoo
    Contributor

    Closing, as with new variables resolver it can be solved by passing raw option to variable config, as:

    ${ssm(raw):/aws/reference/secretsmanager/my/env/var/here}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions