Search code examples
google-cloud-functionsserverlessserverless-frameworkgoogle-secret-manager

How to get secret from Google Secrets Manager using Serverless?


Using Serverless and AWS it's possible to load secrets from AWS SSM using:

environment:
  KEY: ${ssm(raw):/aws/reference/secretsmanager/prod/KEY}

Is there something equivalent available for Google Secrets Manager? Tried looking into Serverless documentation but couldn't find anything.


Solution

  • The Serverless Google Cloud Functions plugin is actually poorly documented.

    NO, You don't need to write your own plugin for that.

    Serverless Google Cloud Functions does accept references to Secrets Manager out of the box and secrets are exposed as environment variables to your Cloud Functions!

    If you just look into the code itself https://github.com/serverless/serverless-google-cloudfunctions/blob/4e59429ad2857cbc8d95ce70db6b41bed76b67ad/provider/googleProvider.js#L160

    Notice the functions schema accepts a property named secrets. The implementation would look something like this:

    functions:
      my-function:
        handler:  MyFunction
        memorySize: 128
        secrets:
          SendgridAccessToken:
            secret: SENDGRID_ACCESS_TOKEN
            version: latest
        events:
          - event:
              eventType: providers/cloud.pubsub/eventTypes/topic.publish
              resource: ${self:custom.params.EventBus}
    

    Hope this is what you were looking for!