在新版本@ aws-cdk / aws-secretsmanager:1.20.0中,secretsmanager.AttachmentTargetType的替代方案是什么?

时间:2020-01-23 08:30:29

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

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。因此我使用了attach。在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)

1 个答案:

答案 0 :(得分:0)

AttachmenTargetType被错误地弃用。

仅弃用其某些常量:secretsmanager.AttachmentTargetType.CLUSTER现在为secretsmanager.AttachmentTargetType.RDS_DB_CLUSTER,而secretsmanager.AttachmentTargetType.INSTANCE现在为secretsmanager.AttachmentTargetType.RDS_DB_INSTANCE

请注意,如果在您的示例中this.database是一个Cluster实例,则可以执行以下操作:

this.dbSecrets.attach(this.database);