Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
How can I create a DependsOn relation between EC2 and RDS using aws-cdk

I am currently using the aws-cdk (TypeScript) to create a stack that consists of an EC2 instance and a RDS databaseInstance.

The RDS instance needs to be setup before the EC2 instance can be started and userdata will be executed.

The problem I have is, that I could not find a way to define the DepensOn (Cloudformation) attribute between the two resources.

The workaround is, that I am using netsted stacks.

The code looks something like this:

const instance = new ec2.Instance(this, 'Instance', {...})
const rdsInstance = new rds.DatabaseInstance(this, 'DbInstance', {...})

Now I would like to define something like instance.dependsOn(rdsInstance).

Did anybody run into the same issue?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report

0

Hope the following helps you.

const instance = new ec2.Instance(this, 'Instance', { /* ... */ }).getInstance();
const rdsInstance = new rds.DatabaseInstance(this, 'DbInstance', { /* ... */ }).getInstance();

instance.addDependsOn(rdsInstance);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!