RemovalPolicy
- class aws_cdk.RemovalPolicy(*values)
Bases:
EnumPossible values for a resource’s Removal Policy.
The removal policy controls what happens to the resource if it stops being managed by CloudFormation. This can happen in one of three situations:
The resource is removed from the template, so CloudFormation stops managing it;
A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it;
The stack is deleted, so CloudFormation stops managing all resources in it.
The Removal Policy applies to all above cases.
Many stateful resources in the AWS Construct Library will accept a
removalPolicyas a property, typically defaulting it toRETAIN.If the AWS Construct Library resource does not accept a
removalPolicyargument, you can always configure it by using the escape hatch mechanism, as shown in the following example:# bucket: s3.Bucket cfn_bucket = bucket.node.find_child("Resource") cfn_bucket.apply_removal_policy(RemovalPolicy.DESTROY)
- ExampleMetadata:
fixture=default infused
Example:
bucket = s3.Bucket(self, "memoryBucket", bucket_name="test-memory", removal_policy=cdk.RemovalPolicy.DESTROY, auto_delete_objects=True ) topic = sns.Topic(self, "topic") # Create a custom semantic memory strategy self_managed_strategy = agentcore.MemoryStrategy.using_self_managed( name="selfManagedStrategy", description="self managed memory strategy", historical_context_window_size=5, invocation_configuration=agentcore.InvocationConfiguration( topic=topic, s3_location=s3.Location( bucket_name=bucket.bucket_name, object_key="memory/" ) ), trigger_conditions=agentcore.TriggerConditions( message_based_trigger=1, time_based_trigger=cdk.Duration.seconds(10), token_based_trigger=100 ) ) # Create memory with custom strategy memory = agentcore.Memory(self, "MyMemory", memory_name="my-custom-memory", description="Memory with custom strategy", expiration_duration=cdk.Duration.days(90), memory_strategies=[self_managed_strategy] )
Attributes
- DESTROY
When this removal policy is applied, the resource will be physically destroyed when it is removed from the stack or when the stack is deleted.
- RETAIN
This uses the ‘Retain’ DeletionPolicy, which will cause the resource to be retained in the account, but orphaned from the stack.
Most resources default to this removal policy.
- RETAIN_ON_UPDATE_OR_DELETE
Resource will be retained when they are requested to be deleted during a stack delete request or need to be replaced due to a stack update request.
Resource are not retained, if the creation is rolled back.
The result is that new, empty, and unused resources are deleted, while in-use resources and their data are retained.
This uses the ‘RetainExceptOnCreate’ DeletionPolicy, and the ‘Retain’ UpdateReplacePolicy, when
applyToUpdateReplacePolicyis set.
- SNAPSHOT
This retention policy deletes the resource, but saves a snapshot of its data before deleting, so that it can be re-created later.
Only available for some stateful resources, like databases, EC2 volumes, etc.