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
To add a dependency on the Bucket itself:
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 thes3deploy.BucketDeployment
:You need to depend on the deployed bucket, which is resolved only when the deployment is complete.
Source: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3_deployment.BucketDeployment.html#deployedbucket