This article does not explain the usual action following retaining, which is the intent to re-use the retained resource in the next stack creation. Regardless of using a custom or auto-generated name, how does one import them? The ".from" static functions on the CDK resources for imports are only pointers to the account resources and cannot be resumed with ongoing modifications to the stack resources.
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
Unfortunately, this post is very disappointing. Is there a way AWS CDK can be smart to automatically import these retained stateful resources back into the stack? That was the resolution I was hoping to see. Correct me if I'm wrong, but if we'd like to keep the date stored in these resources, we'd have to craft a workaround? Perhaps, rename retained resource and write some script / lambda function to import items?
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
What if I want to reuse the resource? That's the main purpose of retaining it in my case also.
Thank you for your comment. We'll review and update the Knowledge Center article as needed.
CDK should automatically import resources that already exist, otherwise it's largely useless for IaC for anything that isn't stateless.
Echoing the replies you have already received on this article. The usual desired behavior is to re-import these already existing resources. You should either explain how to do that manually or implement the behavior for cdk to do this.
I agree with the comments above, we have been facing as well this error with "Resource of type 'AWS::IAM::Role' with identifier 'our-role-name-here' already exists.", although IAM Role have a default removalPolicy property to DESTROY.
I agree, I expected to see a way to deploy changes retaining the bucket containing the data. Should we handle "manually" the import of the arn?
def __get_or_create_s3_bucket(self) -> Bucket:
"""
Retrieves the S3 bucket. If it exists, it is imported. If it
does not exist, a new bucket is created.
:return: The S3 Bucket
"""
bucket_arn = Fn.sub("arn:aws:s3:::${bucketName}", {"bucketName": self.bucket_name})
try:
# Attempt to import the bucket.
bucket = Bucket.from_bucket_arn(self.stack, self.bucket_id, bucket_arn)
print(f"Imported existing bucket: {self.bucket_name}")
return bucket
Relevant content
- asked 10 months ago
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago