【问题标题】:What is the alternative for secretsmanager.AttachmentTargetType in new version @aws-cdk/aws-secretsmanager: 1.20.0?在新版本 @aws-cdk/aws-secretsmanager: 1.20.0 中,secretsmanager.AttachmentTargetType 的替代方案是什么?
【发布时间】:2020-05-09 11:19:19
【问题描述】:

使用 1.19.0 版本,下面的脚本可以正常工作。

  import secretsmanager = require('@aws-cdk/aws-secretsmanager');
  const target : secretsmanager.ISecretAttachmentTarget = {
            asSecretAttachmentTarget: () => ({
                targetId: `arn:aws:rds:${this.region}:${this.account}:cluster:${this.database.ref}`,
                targetType: secretsmanager.AttachmentTargetType.CLUSTER
            })
        };

   const myUserSecretAttached = this.dbSecrets.addTargetAttachment('AttachedSecret', {target})

对于 1.20.0 版本,不推荐使用 addTargetAttachment。所以我使用了附加。在 ISecretAttachmentTarget 中,不推荐使用 targetType 'secretsmanager.AttachmentTargetType'。那么有什么选择呢? 我尝试了以下脚本,该脚本会引发错误“已使用已弃用的符号,请查阅文档以获得更好的替代方案。”

 import secretsmanager = require('@aws-cdk/aws-secretsmanager');
  const target : secretsmanager.ISecretAttachmentTarget = {
            asSecretAttachmentTarget: () => ({
                targetId: `arn:aws:rds:${this.region}:${this.account}:cluster:${this.database.ref}`,
                targetType: secretsmanager.AttachmentTargetType.CLUSTER
            })
        };

   const myUserSecretAttached = this.dbSecrets.attach(target)

【问题讨论】:

    标签: amazon-rds aws-cdk aws-secrets-manager


    【解决方案1】:

    AttachmenTargetType 已被错误地弃用。

    只有部分常量被弃用:secretsmanager.AttachmentTargetType.CLUSTER 现在是 secretsmanager.AttachmentTargetType.RDS_DB_CLUSTERsecretsmanager.AttachmentTargetType.INSTANCE 现在是 secretsmanager.AttachmentTargetType.RDS_DB_INSTANCE

    请注意,如果在您的示例中 this.databaseCluster 实例,您可以简单地这样做:

    this.dbSecrets.attach(this.database);
    

    【讨论】:

    • 嗨@jogold,this.dbSecrets.attach(this.database) 抛出错误“CfnDBCluster 类型的参数不可分配给 ISecretAttachmentTarget 类型的参数”。
    • 我说如果this.clusterCluster 实例而不是CfnCluster 实例。此外,这已被合并github.com/aws/aws-cdk/pull/5950
    猜你喜欢
    • 2020-12-16
    • 1970-01-01
    • 2020-07-18
    • 2019-09-25
    • 1970-01-01
    • 2022-11-01
    • 2021-09-26
    • 2020-08-25
    • 2021-04-18
    相关资源
    最近更新 更多