DatabaseSecret
- class aws_cdk.aws_docdb.DatabaseSecret(scope, id, *, username, encryption_key=None, exclude_characters=None, master_secret=None, secret_name=None)
Bases:
Secret
A database secret.
- Resource:
AWS::SecretsManager::Secret
- ExampleMetadata:
infused
Example:
# cluster: docdb.DatabaseCluster my_user_secret = docdb.DatabaseSecret(self, "MyUserSecret", username="myuser", master_secret=cluster.secret ) my_user_secret_attached = my_user_secret.attach(cluster) # Adds DB connections information in the secret cluster.add_rotation_multi_user("MyUser", # Add rotation using the multi user scheme secret=my_user_secret_attached)
- Parameters:
scope (
Construct
) –id (
str
) –username (
str
) – The username.encryption_key (
Optional
[IKey
]) – The KMS key to use to encrypt the secret. Default: default master keyexclude_characters (
Optional
[str
]) – Characters to not include in the generated password. Default: “”master_secret (
Optional
[ISecret
]) – The master secret which will be used to rotate this secret. Default: - no master secret information will be includedsecret_name (
Optional
[str
]) – The physical name of the secret. Default: Secretsmanager will generate a physical name for the secret
Methods
- add_replica_region(region, encryption_key=None)
Adds a replica region for the secret.
- Parameters:
region (
str
) – The name of the region.encryption_key (
Optional
[IKey
]) – The customer-managed encryption key to use for encrypting the secret value.
- Return type:
None
- add_rotation_schedule(id, *, automatically_after=None, hosted_rotation=None, rotation_lambda=None)
Adds a rotation schedule to the secret.
- Parameters:
id (
str
) –automatically_after (
Optional
[Duration
]) – Specifies the number of days after the previous rotation before Secrets Manager triggers the next automatic rotation. A value of zero will disable automatic rotation -Duration.days(0)
. Default: Duration.days(30)hosted_rotation (
Optional
[HostedRotation
]) – Hosted rotation. Default: - eitherrotationLambda
orhostedRotation
must be specifiedrotation_lambda (
Optional
[IFunction
]) – A Lambda function that can rotate the secret. Default: - eitherrotationLambda
orhostedRotation
must be specified
- Return type:
- add_target_attachment(id, *, target)
(deprecated) Adds a target attachment to the secret.
- Parameters:
id (
str
) –target (
ISecretAttachmentTarget
) – The target to attach the secret to.
- Return type:
- Returns:
an AttachedSecret
- Deprecated:
use
attach()
instead- Stability:
deprecated
- add_to_resource_policy(statement)
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.- Parameters:
statement (
PolicyStatement
) –- Return type:
- apply_removal_policy(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
).- Parameters:
policy (
RemovalPolicy
) –- Return type:
None
- attach(target)
Attach a target to this secret.
- Parameters:
target (
ISecretAttachmentTarget
) – The target to attach.- Return type:
- Returns:
An attached secret
- deny_account_root_delete()
Denies the
DeleteSecret
action to all principals within the current account.- Return type:
None
- grant_read(grantee, version_stages=None)
Grants reading the secret value to some role.
- Parameters:
grantee (
IGrantable
) –version_stages (
Optional
[Sequence
[str
]]) –
- Return type:
- grant_write(grantee)
Grants writing and updating the secret value to some role.
- Parameters:
grantee (
IGrantable
) –- Return type:
- secret_value_from_json(json_field)
Interpret the secret as a JSON object and return a field’s value from it as a
SecretValue
.- Parameters:
json_field (
str
) –- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- encryption_key
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.
- env
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
The construct tree node associated with this construct.
- secret_arn
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 thesecretName
.
- secret_full_arn
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).
- secret_name
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.
- secret_value
Retrieve the value of the stored secret as a
SecretValue
.
- stack
The stack in which this resource is defined.
Static Methods
- classmethod from_secret_arn(scope, id, secret_arn)
- classmethod from_secret_attributes(scope, id, *, encryption_key=None, secret_arn=None, secret_complete_arn=None, secret_partial_arn=None)
Import an existing secret into the Stack.
- Parameters:
scope (
Construct
) – the scope of the import.id (
str
) – the ID of the imported Secret in the construct tree.encryption_key (
Optional
[IKey
]) – The encryption key that is used to encrypt the secret, unless the default SecretsManager key is used.secret_arn (
Optional
[str
]) – (deprecated) The ARN of the secret in SecretsManager. Cannot be used withsecretCompleteArn
orsecretPartialArn
.secret_complete_arn (
Optional
[str
]) – The complete ARN of the secret in SecretsManager. This is the ARN including the Secrets Manager 6-character suffix. Cannot be used withsecretArn
orsecretPartialArn
.secret_partial_arn (
Optional
[str
]) – The partial ARN of the secret in SecretsManager. This is the ARN without the Secrets Manager 6-character suffix. Cannot be used withsecretArn
orsecretCompleteArn
.
- Return type:
- classmethod from_secret_complete_arn(scope, id, secret_complete_arn)
Imports a secret by complete ARN.
The complete ARN is the ARN with the Secrets Manager-supplied suffix.
- classmethod from_secret_name(scope, id, secret_name)
(deprecated) Imports a secret by secret name;
the ARN of the Secret will be set to the secret name. A secret with this name must exist in the same account & region.
- classmethod from_secret_name_v2(scope, id, secret_name)
Imports a secret by secret name.
A secret with this name must exist in the same account & region. Replaces the deprecated
fromSecretName
.
- classmethod from_secret_partial_arn(scope, id, secret_partial_arn)
Imports a secret by partial ARN.
The partial ARN is the ARN without the Secrets Manager-supplied suffix.
- classmethod is_construct(x)
Return whether the given object is a Construct.
- Parameters:
x (
Any
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool