class DatabaseSecret (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.DocDB.DatabaseSecret |
Java | software.amazon.awscdk.services.docdb.DatabaseSecret |
Python | aws_cdk.aws_docdb.DatabaseSecret |
TypeScript (source) | @aws-cdk/aws-docdb » DatabaseSecret |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, ISecret
A database secret.
Example
declare const cluster: docdb.DatabaseCluster;
const myUserSecret = new docdb.DatabaseSecret(this, 'MyUserSecret', {
username: 'myuser',
masterSecret: cluster.secret,
});
const myUserSecretAttached = myUserSecret.attach(cluster); // Adds DB connections information in the secret
cluster.addRotationMultiUser('MyUser', { // Add rotation using the multi user scheme
secret: myUserSecretAttached, // This secret must have the `masterarn` key
});
Initializer
new DatabaseSecret(scope: Construct, id: string, props: DatabaseSecretProps)
Parameters
- scope
Construct
- id
string
- props
Database
Secret Props
Construct Props
Name | Type | Description |
---|---|---|
username | string | The username. |
encryption | IKey | The KMS key to use to encrypt the secret. |
exclude | string | Characters to not include in the generated password. |
master | ISecret | The master secret which will be used to rotate this secret. |
secret | string | The physical name of the secret. |
username
Type:
string
The username.
encryptionKey?
Type:
IKey
(optional, default: default master key)
The KMS key to use to encrypt the secret.
excludeCharacters?
Type:
string
(optional, default: "")
Characters to not include in the generated password.
masterSecret?
Type:
ISecret
(optional, default: no master secret information will be included)
The master secret which will be used to rotate this secret.
secretName?
Type:
string
(optional, default: Secretsmanager will generate a physical name for the secret)
The physical name of the secret.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Construct | The construct tree node associated with this construct. |
secret | string | The ARN of the secret in AWS Secrets Manager. |
secret | string | The name of the secret. |
secret | Secret | Retrieve the value of the stored secret as a SecretValue . |
stack | Stack | The stack in which this resource is defined. |
encryption | IKey | The customer-managed encryption key that is used to encrypt this secret, if any. |
secret | string | The full ARN of the secret in AWS Secrets Manager, which is the ARN including the Secrets Manager-supplied 6-character suffix. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
node
Type:
Construct
The construct tree node associated with this construct.
secretArn
Type:
string
The ARN of the secret in AWS Secrets Manager.
Will return the full ARN if available, otherwise a partial arn.
For secrets imported by the deprecated fromSecretName
, it will return the secretName
.
secretName
Type:
string
The name of the secret.
For "owned" secrets, this will be the full resource name (secret name + suffix), unless the '@aws-cdk/aws-secretsmanager:parseOwnedSecretName' feature flag is set.
secretValue
Type:
Secret
Retrieve the value of the stored secret as a SecretValue
.
stack
Type:
Stack
The stack in which this resource is defined.
encryptionKey?
Type:
IKey
(optional)
The customer-managed encryption key that is used to encrypt this secret, if any.
When not specified, the default KMS key for the account and region is being used.
secretFullArn?
Type:
string
(optional)
The full ARN of the secret in AWS Secrets Manager, which is the ARN including the Secrets Manager-supplied 6-character suffix.
This is equal to secretArn
in most cases, but is undefined when a full ARN is not available (e.g., secrets imported by name).
Methods
Name | Description |
---|---|
add | Adds a replica region for the secret. |
add | Adds a rotation schedule to the secret. |
add | Adds a target attachment to the secret. |
add | Adds a statement to the IAM resource policy associated with this secret. |
apply | Apply the given removal policy to this resource. |
attach(target) | Attach a target to this secret. |
deny | Denies the DeleteSecret action to all principals within the current account. |
grant | Grants reading the secret value to some role. |
grant | Grants writing and updating the secret value to some role. |
secret | Interpret the secret as a JSON object and return a field's value from it as a SecretValue . |
to | Returns a string representation of this construct. |
ReplicaRegion(region, encryptionKey?)
addpublic addReplicaRegion(region: string, encryptionKey?: IKey): void
Parameters
- region
string
— The name of the region. - encryptionKey
IKey
— The customer-managed encryption key to use for encrypting the secret value.
Adds a replica region for the secret.
RotationSchedule(id, options)
addpublic addRotationSchedule(id: string, options: RotationScheduleOptions): RotationSchedule
Parameters
- id
string
- options
Rotation
Schedule Options
Returns
Adds a rotation schedule to the secret.
TargetAttachment(id, options)
addpublic addTargetAttachment(id: string, options: AttachedSecretOptions): SecretTargetAttachment
⚠️ Deprecated: use attach()
instead
Parameters
- id
string
- options
Attached
Secret Options
Returns
Adds a target attachment to the secret.
ToResourcePolicy(statement)
addpublic addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
Statement
Returns
Adds a statement to the IAM resource policy associated with this secret.
If this secret was created in this stack, a resource policy will be
automatically created upon the first call to addToResourcePolicy
. If
the secret is imported, then this is a no-op.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
attach(target)
public attach(target: ISecretAttachmentTarget): ISecret
Parameters
- target
ISecret
— The target to attach.Attachment Target
Returns
Attach a target to this secret.
AccountRootDelete()
denypublic denyAccountRootDelete(): void
Denies the DeleteSecret
action to all principals within the current account.
Read(grantee, versionStages?)
grantpublic grantRead(grantee: IGrantable, versionStages?: string[]): Grant
Parameters
- grantee
IGrantable
- versionStages
string[]
Returns
Grants reading the secret value to some role.
Write(grantee)
grantpublic grantWrite(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grants writing and updating the secret value to some role.
ValueFromJson(jsonField)
secretpublic secretValueFromJson(jsonField: string): SecretValue
Parameters
- jsonField
string
Returns
Interpret the secret as a JSON object and return a field's value from it as a SecretValue
.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.