Benjamim Freitas
Benjamim Freitas

Reputation: 13

Serverless get SSM parameter by hierarchy path

is there a way to retrieve multiple ssm parameters through serverless.yml into an environment variable?

for example right now i have the parameters: "/dev/db/user" and "/dev/db/password" and on serverless.yml:

environment:
  DB_USER: ${ssm:/${self:custom.stage}/db/user}
  DB_PASSWORD: ${ssm:/${self:custom.stage}/db/password}

where custom.stage will be dev/prod etc.

problem is there will be more db info, hostname, port maybe more who knows, so is there a way to retrieve everything into a single environment variable?

i thought about using a single ssm parameter with a json string with all the info and parse it in the cloud function, but maybe there is something more like the aws cli command: aws ssm get-parameters-by-path --path "/dev/db" that is exactly what i need but for serverless

Upvotes: 1

Views: 687

Answers (1)

karjan
karjan

Reputation: 1016

You can use Join function to combine multiple values. Something like:

 environment:
    DB_XXX: ${ssm:/${self:custom.stage}/db/user}
      Fn::Join:
        - "-"
        - - ${ssm:/${self:custom.stage}/db/x1}
          - ${ssm:/${self:custom.stage}/db/x2}

Upvotes: 1

Related Questions