Accessing AWS Secrets Manager From Lambda
AWS Secrets Manager is a key, password and credential storage tool provided in AWS. It allows the for the secure encryption and rotation of keys and can the keys can be accessed by other resources.
Node js Lambda and Secrets Manager
The important aspect to note about this code is that the
client.getSecretValue is an async function.
That is why the function is wrapped in a promise and we call the function with the
await syntax so that the lambda doesn’t terminate before the secret has been retrieved from Secrets Manager.
AWS Roles. Secrets Manager Policy
In order for your AWS resources to access Secrets Manager, the resources needs to have the correct permissions to do so.
This means that when you assign a role to your lambda, that role must have the SecretsManagerReadWrite policy attached to it to give it the required permission to access Secrets Manager.