【问题标题】:Make Quicksight resource depend on an s3 bucket creation in AWS CDK使 Quicksight 资源依赖于 AWS CDK 中的 s3 存储桶创建
【发布时间】:2023-01-13 06:08:13
【问题描述】:

我有一个 s3 存储桶,它在 CDK 中创建时上传清单文件。

Quicksight 中的数据集随后会使用此清单文件。但是我的 CDK 部署失败了,因为 QuickSight 无法找到 S3 中的清单文件。所以我想为 Quicksight 资源添加一个 dependsOn

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)

我收到类似这样的错误:Argument of type 'Bucket' is not assignable to parameter of type 'CfnResource'

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation aws-cdk


    【解决方案1】:

    要添加对 Bucket 本身的依赖:

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

    不过,这可能不是您想要的。这确保了在创建 QuickSight 资源之前存在。它不能确保您的manifest.json数据在桶里。为此,改为添加对 s3deploy.BucketDeployment 部署的自定义资源的依赖:

    quicksightDatasource.addDependency(
        bucketDeployment.node.tryFindChild("CustomResource")?.node.defaultChild as CfnCustomResource
    );
    

    【讨论】:

      【解决方案2】:

      需要依赖已部署的bucket,部署完成后才会解析。

      quicksightDatasource.addDependency(bucketDeployment.deployedBucket)
      

      如果您想在另一个构造中引用目标存储桶并确保在下一个操作开始之前已经部署了存储桶,请将另一个构造传递给deployment.deployedBucket

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-16
        • 1970-01-01
        • 2020-05-28
        • 2020-05-04
        • 1970-01-01
        • 1970-01-01
        • 2020-05-26
        • 1970-01-01
        相关资源
        最近更新 更多