SecretTargetAttachment
- class aws_cdk.aws_secretsmanager.SecretTargetAttachment(scope, id, *, secret, target)
Bases:
Resource
An attached secret.
- ExampleMetadata:
fixture=_generated
Example:
# The code below shows an example of how to instantiate this type. # The values are placeholders you should change. from aws_cdk import aws_secretsmanager as secretsmanager # secret: secretsmanager.Secret # secret_attachment_target: secretsmanager.ISecretAttachmentTarget secret_target_attachment = secretsmanager.SecretTargetAttachment(self, "MySecretTargetAttachment", secret=secret, target=secret_attachment_target )
- Parameters:
scope (
Construct
) –id (
str
) –secret (
ISecret
) – The secret to attach to the target.target (
ISecretAttachmentTarget
) – The target to attach the secret to.
Methods
- add_rotation_schedule(id, *, automatically_after=None, hosted_rotation=None, rotate_immediately_on_update=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. The minimum value is 4 hours. The maximum value is 1000 days. A value of zero (Duration.days(0)
) will not create RotationRules. Default: Duration.days(30)hosted_rotation (
Optional
[HostedRotation
]) – Hosted rotation. Default: - eitherrotationLambda
orhostedRotation
must be specifiedrotate_immediately_on_update (
Optional
[bool
]) – Specifies whether to rotate the secret immediately or wait until the next scheduled rotation window. Default: truerotation_lambda (
Optional
[IFunction
]) – A Lambda function that can rotate the secret. Default: - eitherrotationLambda
orhostedRotation
must be specified
- Return type:
- add_to_resource_policy(statement)
Forward any additions to the resource policy to the original secret.
This is required because a secret can only have a single resource policy. If we do not forward policy additions, a new policy resource is created using the secret attachment ARN. This ends up being rejected by CloudFormation.
- 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 tree node.
- 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_target_attachment_secret_arn
Same as
secretArn
.- Attribute:
true
- 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_target_attachment_secret_arn(scope, id, secret_target_attachment_secret_arn)
- Parameters:
scope (
Construct
) –id (
str
) –secret_target_attachment_secret_arn (
str
) –
- Return type:
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
instances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructs
library on disk are seen as independent, completely different libraries. As a consequence, the classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
the other class.npm install
will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool