How can I create a DependsOn relation between EC2 and RDS using aws-cdk
Hope the following helps you.
const instance = new ec2.Instance(this, 'Instance', { /* ... */ }).getInstance();
const rdsInstance = new rds.DatabaseInstance(this, 'DbInstance', { /* ... */ }).getInstance();
instance.addDependsOn(rdsInstance);
The solution here is to use addDependency()
on the node
, this will handle all the necessary CloudFormation DependsOn
for you:
const instance = new ec2.Instance(this, 'Instance', {...});
const rdsInstance = new rds.DatabaseInstance(this, 'DbInstance', {...});
rdsInstance.node.addDependency(instance);
From the JSDoc of addDependency()
: Add an ordering dependency on another Construct. All constructs in the dependency's scope will be deployed before any construct in this construct's scope.