Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

amazon web services - How can I reference a object value from secret manager in serverless.yml?

I am deploying apps to AWS via serverless. And need to read values from secretmanager during deployment. I have read this doc: https://www.serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-using-the-ssm-parameter-store

it shows how to read it:

custom: supersecret: ${ssm:/aws/reference/secretsmanager/secret_ID_in_Secrets_Manager~true} however, it can be used to read a string value from secret manager. My secret is an object which includes key/value pairs. How can I read the key inside a secret?

I have tried something like this:

custom: supersecret: ${ssm:/aws/reference/secretsmanager/secret_ID_in_Secrets_Manager:MY_KEY~true}

custom: supersecret: ${ssm:/aws/reference/secretsmanager/secret_ID_in_Secrets_Manager/MY_KEY~true}

but none of them working.

question from:https://stackoverflow.com/questions/65949994/how-can-i-reference-a-object-value-from-secret-manager-in-serverless-yml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Serverless will resolve the object for you.

Assuming that the content of your secret_ID_in_Secrets_Manager looks like this:

{
  "foo": "foo",
  "bar": "bar"
}

Then if you define your custom variable in serverless.yml like this:

custom:
  supersecret: ${ssm:/aws/reference/secretsmanager/secret_ID_in_Secrets_Manager~true}

Then this will resolve to:

custom:
  supersecret:
    foo: foo
    bar: bar

You can reference them inside serverless.yml by using ${self:custom.supersecret.foo} and ${self:custom.supersecret.bar}.

See the Serverless documentation and search for Variables can also be object, since AWS Secrets Manager can store secrets not only in plain text but also in JSON..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...