What's the @aws-cdk/rds equivalent of add-role-to-db-instance (lambda invoke from postgres rds instance)? #20276
-
Hi all - I'm looking at implementing the steps outlined at https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL-Lambda.html on an existing RDS instance via a cdk script, and I've figured out how to use
There doesn't seem to be a method I can find on I thought it might be as simple as Am I missing something, or is this just not possible to do? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Since the underlying CloudFormation resource const instanceRole = new iam.Role(this, 'RDSLambdaRole', {
assumedBy: new iam.ServicePrincipal('rds.amazonaws.com'),
roleName: 'rds-lambda-role',
description: 'Give RDS Postgres instance permission to invoke lambda',
inlinePolicies: {
InstanceConnectPolicy: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ['lambda:InvokeFunction'],
resources: [
`arn:aws:lambda:${Stack.of(this).region}:${Stack.of(this).account}:function:${lambdaName}`,
],
}),
],
}),
},
});
const instance = new rds.DatabaseInstance(this, 'Instance', { ... });
const cfnInstance = instance.node.defaultChild as rds.CfnDBInstance;
cfnInstance.associatedRoles = [
{
featureName: 'Lambda', // supported FeatureNames: ["Lambda", "s3Export", "s3Import"]
roleArn: instanceRole.roleArn,
},
]; |
Beta Was this translation helpful? Give feedback.
-
Used AwsSdkCall AwsCustomResource. Works as expected.
|
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Since the underlying CloudFormation resource
AWS::RDS::DBInstance
has the AssociatedRoles property that refers to roles associated with the DB instance, it's possible to modify the CDK resource using thenode
field: