skip to Main Content

I got a s3 bucket where that uploads a manifest file on creation in CDK.

This manifest file is then use by an Dataset in Quicksight. But my CDK deployment fails because the manifest file in S3 can’t be found by QuickSight. So I want to add a dependsOn for the Quicksight resource.

const quicksightBucket = new s3.Bucket(this, "userS3Bucket", {
            bucketName: "quicksight-bucket-user",
            blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
            versioned: true,
            removalPolicy: cdk.RemovalPolicy.DESTROY,
            autoDeleteObjects: true,
        })

        const bucketDeployment = new s3deploy.BucketDeployment(
            this,
            "bucketDeployment",
            {
                destinationBucket: quicksightBucket,
                sources: [
                    s3deploy.Source.asset("/Users/user/Downloads/housing"),
                ],
            }
        )

                const quicksightDatasource = new quicksight.CfnDataSource(
            this,
            "quicksight-datasource",
            {
                name: "quicksightdatasource",
                awsAccountId: "123123",
                dataSourceId: "7217623409123897423687",
                type: "S3",
                dataSourceParameters: {
                    s3Parameters: {
                        manifestFileLocation: {
                            bucket: quicksightBucket.bucketName,
                            key: "manifest.json",
                        },
                    },
                },
            }
        )

        quicksightDatasource.addDependsOn(bucketDeployment)

I’m getting an error like: Argument of type 'Bucket' is not assignable to parameter of type 'CfnResource'.

2

Answers


  1. To add a dependency on the Bucket itself:

    quicksightDatasource.addDependency(
        quicksightBucket.node.defaultChild as s3.CfnBucket
    );
    

    That’s probably not what you want, though. That ensures the bucket exists before the QuickSight resource is created. It doesn’t ensure your manifest.json data are in the bucket. To do that, instead add a dependency on the Custom Resource that’s deployed by the s3deploy.BucketDeployment:

    quicksightDatasource.addDependency(
        bucketDeployment.node.tryFindChild("CustomResource")?.node.defaultChild as CfnCustomResource
    );
    
    Login or Signup to reply.
  2. You need to depend on the deployed bucket, which is resolved only when the deployment is complete.

    quicksightDatasource.addDependency(bucketDeployment.deployedBucket)
    

    If you want to reference the destination bucket in another construct and make sure the bucket deployment has happened before the next operation is started, pass the other construct a reference to deployment.deployedBucket.

    Source: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.BucketDeployment.html#deployedbucket

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search