How to retrieve SecretsManager secret in AWS CDK

Question:

I’m setting up a Fargate service in AWS using CDK

How am I supposed to get hold of the ISecret instance given the name of the secret?

I’ve looked at the AWS.SecretsManager from the AWS SDK, but it only returns strings.

Answer:

Currently there is no Secret.fromSecretName-method. Assuming that you are using an existing secret, you should use the Secret.fromSecretArn-method.

Note that if you use a KMS key, you should use the Secret.fromSecretAttributes-method as described at Get a value from AWS secrets manager.

Leave a Reply