0

with version 1.19.0 , below script works fine.

  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})

with version 1.20.0, addTargetAttachment is deprecated.So I have used attach. In ISecretAttachmentTarget targetType ' secretsmanager.AttachmentTargetType' is deprecated. so what is the alternative ? I have tried the below script which throws error 'Deprecated symbol used, consult docs for better alternative.'

 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)
James_RajKumar
  • 201
  • 3
  • 12

1 Answers1

0

AttachmenTargetType has been wrongly deprecated.

Only some of its constants are deprecated: secretsmanager.AttachmentTargetType.CLUSTER is now secretsmanager.AttachmentTargetType.RDS_DB_CLUSTER and secretsmanager.AttachmentTargetType.INSTANCE is now secretsmanager.AttachmentTargetType.RDS_DB_INSTANCE.

Note that if in your example this.database is a Cluster instance, you can simply do:

this.dbSecrets.attach(this.database);
jogold
  • 6,667
  • 23
  • 41
  • hi @jogold , `this.dbSecrets.attach(this.database)` throws error 'Argument of type CfnDBCluster is not assignable to parameter of type ISecretAttachmentTarget'. – James_RajKumar Jan 30 '20 at 07:05
  • I said if `this.cluster` is a `Cluster` instance not a `CfnCluster` instance. Also, this has been merged https://github.com/aws/aws-cdk/pull/5950 – jogold Jan 30 '20 at 07:22