I'm reading the CDK docs about the SecretsManager and I'm not sure if I've mis-understood, but what I thought would work from their example doesn't seem to grant the permission I expected. Essentially I have a stack that contains some Lambdas, and I'd like all of them to be able to Read two secrets from the SecretsManager.
class CdkStack extends cdk.Stack {
/**
*
* @param {cdk.Construct} scope
* @param {string} id
* @param {cdk.StackProps=} props
*/
constructor(scope, id, props) {
super(scope, id, props);
// eslint-disable-next-line no-new
new APIServices(this, "APIServices");
const role = new iam.Role(this, "SecretsManagerRead", {
assumedBy: new iam.AccountRootPrincipal(),
});
const dbReadSecret = new secretsmanager.Secret(this, "databaseReader");
const dbWriteSecret = new secretsmanager.Secret(this, "databaseWriter");
dbReadSecret.grantRead(role);
dbWriteSecret.grantRead(role);
}
}
If I understood it correctly I should simply create this role and give it permissions to access secrets? My Lambda's still however failed when I tried to run them. Do I need to do anything else not mentioned in the docs I was reading about assigning that role to the Lambdas explicitly too?