Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_s3_deployment.BucketDeployment: default_child not useable as dependency #32253

Closed
1 task
gratinierer opened this issue Nov 22, 2024 · 2 comments
Closed
1 task
Assignees
Labels
@aws-cdk/aws-s3-deployment bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@gratinierer
Copy link

Describe the bug

Using a aws_s3_deployment.BucketDeployment and trying do add this deployment as dependency does not work.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

i would expect, that I can add a BucketDeployment as dependency to another L1-Constructs, as can do e.g. with aws_s3.Bucket

Current Behavior

TypeError: type of argument target must be aws_cdk.CfnResource; got NoneType instead

is thrown

Reproduction Steps

 deployment = aws_s3_deployment.BucketDeployment(self,
                                                                        'DeploymentBucketDeployment',
                                                                        sources=[aws_s3_deployment.Source.asset(
                                                                            zip_file)],
                                                                        extract=True,
                                                                        destination_bucket=deployment_bucket
                                                                        )
  cfn_application_version = aws_cdk.aws_elasticbeanstalk.CfnApplicationVersion(
            self, "MyCfnApplicationVersion",
            application_name="application",
            source_bundle=aws_cdk.aws_elasticbeanstalk.CfnApplicationVersion.SourceBundleProperty(
                s3_bucket=deplomyent_bucket_name,
                s3_key=deployment_artifact
            ),
        )
        cfn_application_version.add_dependency(deployment.node.default_child)

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.148.0 (build e5740c0)

Framework Version

No response

Node.js Version

20.15

OS

Win10

Language

Python

Language Version

No response

Other information

No response

@gratinierer gratinierer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2024
@ashishdhingra ashishdhingra self-assigned this Nov 22, 2024
@ashishdhingra ashishdhingra added p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 22, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Nov 22, 2024

@gratinierer Good morning. Thanks for reporting the issue. Using the below CDK code (in TypeScript):

import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
import path = require('path');
import * as s3Deployment from 'aws-cdk-lib/aws-s3-deployment';

export class CdktestStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const s3TestDeployment = new s3Deployment.BucketDeployment(this, 'TestBucketDeployment', {
      sources:[s3Deployment.Source.asset(path.join(__dirname, 'source-files'))],
      destinationBucket: s3.Bucket.fromBucketName(this, 'MyBucket', 'testbucket-issue32253')
    });

    console.log("s3TestDeployment.node.defaultChild instanceof cdk.Resource: " + (s3TestDeployment.node.defaultChild instanceof cdk.Resource));
    console.log("s3TestDeployment.node.defaultChild === undefined: " + (s3TestDeployment.node.defaultChild === undefined));

    const newBucket = new s3.Bucket(this, 'NewBucket');
    console.log("newBucket.node.defaultChild instanceof cdk.Resource: "+  (newBucket.node.defaultChild instanceof cdk.Resource));
    console.log("newBucket.node.defaultChild === undefined: "+  (newBucket.node.defaultChild === undefined));
  }
}

And running cdk synth produces the below output:

s3TestDeployment.node.defaultChild instanceof cdk.Resource: false
s3TestDeployment.node.defaultChild === undefined: true
newBucket.node.defaultChild instanceof cdk.Resource: false
newBucket.node.defaultChild === undefined: false
...
<<CFN Template YAML>>

If you check the code documentation for node.defaultChild, it @returns — a construct or undefined if there is no default child.

Also in above output, the defaultChild for a BucketDeployment is not defined, hence it cannot be used as a dependency (in Python CDK, undefined is represented as NoneType).

The most likely reason for defaultChild not defined is that BucketDeployment doesn't represents a resource where per code, BucketDeployment extends Construct (compare it to Bucket class, which extends BucketBase which further extends Resource). And this makes sense since BucketDeployment construct represents a deployment operation. And per CloudFormation DependsOn attribute documentation, it specifies that the creation of a specific resource follows another resource.

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed p2 investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 22, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3-deployment bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants