CDK attempts to build ElasticBeanstalk app version before app despite using addDependency.


Issue: Using CDK Pipeline, CloudFormation attempts to build ElasticBeanstalk app version before app despite using addDependency. CloudFormation must build App resource before AppVersion resource to successfully build the ElasticBeanstalk resource.

Failure occurs in the "Prepare" step of the stage.

What I've tried: I'm attempting to use ElasticBeanstalk for my compute with the following code:

    const app = new CfnApplication(this, 'AppElasticBeanstalkApplication', {
      applicationName: props.appName,

    const appVersion = new CfnApplicationVersion(this, 'AppElasticBeanstalkVersion', {
      applicationName: props.appName,
      sourceBundle: {
        s3Bucket: props.s3Bucket,
        s3Key: props.s3Key,

    const elbEnv = new CfnEnvironment(this, 'AppElasticBeanstalkEnvironment', {
      environmentName: props.envName,
      applicationName: props.appName,
      solutionStackName: 'Node.js 18 running on 64bit Amazon Linux 2/5.8.4',
      optionSettings: [
            namespace: 'aws:autoscaling:launchconfiguration',
            optionName: 'InstanceType',
            value: 't3.small',
            namespace: 'aws:autoscaling:launchconfiguration',
            optionName: 'IamInstanceProfile',
            value: 'aws-elasticbeanstalk-ec2-role',
            namespace: 'aws:elasticbeanstalk:container:nodejs',
            optionName: 'NodeVersion',
            value: '18.12.1',
      versionLabel: appVersion.ref,
     // Dependencies.

In CloudFormation, however, I'm seeing:

Resource handler returned message: "No Application named xyz found. (Service: ElasticBeanstalk, Status Code: 400 ...

And indeed in the events history, I can see that the AppVersion resource has status "Resource creation Initiated" prior to the App. I've also tried appVersion.addDependendsOn(app) which shows the same behavior. It's as if these methods aren't actually doing anything.

How can I get these resources to be built in the proper order?

1 Answer

From looking at the code shared at the following URL, I thought your code would work fine.
Is "elbEnv.addDependency(app);" necessary?
Wouldn't it be "elbEnv.addDependency(appVersion);"?

profile picture
answered a year ago
  • Ah, yes that would make more sense. Just tried changing it to "elbEnv.addDependency(appVersion)" and the problem persists.

  • Can you confirm that DependsOn is set in the CloudFormation template by running "cdk synth"? Also, are you using the latest version of CDK?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions