OpenSearch Serverless needs replacing with CloudFormation

0

I am building an app with CDK (js) and CloudFormation. I'm using the CfnCollection construct to stand up the OpenSearch Serverless Collection. Everything works fine, but every so often when deploying my app I receive the following error:

ServerlessSearchStack AWS::OpenSearchServerless::Collection UPDATE_FAILED CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename e1jd2h514ya7a8m11234 and update the stack again.

Some research tells me that sometimes resources need replacing, and CloudFormation cannot do this if a custom name was used for that resource. So my initial thought is ok, I will not give my collection a custom name, but CDK requires a name to instantiate a collection. So that does not appear to be an option.

This error gets my app in a state where I cannot deploy without deleting the OpenSearch Serverless Collection, which deletes all data. Furthermore, I have other stacks that are dependent on that OpenSearch Collection, so those in turn need to be deleted first. This is clearly very disruptive and not tenable in the long run. It causes serious down time for my app. I came across this article on CloudFormation needing to replace resources but it isn't particularly helpful.

What causes my AWS OpenSearch Serverless Collection to need replacing? How can I avoid this? I am wondering if the configs of my dependent stacks are triggering a replacement. However, lately it has been needing to be replaced seemingly without any CloudFormation or infrastructure changes whatsoever. Could it have something to do with updating roles? But again, even when I seemingly change nothing it just decides it needs replacing.

How can remedy this error without completely tearing down my app's stacks and rebuilding? This causes serious downtime for my app. One way I have tried is renaming the collection name in code and sometimes that works, but it does result in all data being loss.

Is it possible CDK could be updated to not require the name property when instantiating a collection? Would that help prevent the data loss and CloudFormation would be able to do the replacement on its own?

1 Answer
0
Accepted Answer

The Name property is required in the CloudFormation resource (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-opensearchserverless-collection.html#cfn-opensearchserverless-collection-name), hence why it is required in the CDK construct.

It appears that the properties that trigger resources replacement are Name, Type and Tags for the AWS::OpenSearchServerless::Collection resource. Are you aware of any changes to the tags that may be causing CloudFormation to attempt to replace the collection? Are you able to run a cdk diff to inspect the changes prior to deploying them?

AWS
Mike_A
answered 7 days ago
  • Thank You Mike A! I have confirmed it was a changing of the Tags that was triggering a replacement. We have automated releases which were bumping a version tag. I am going to remove the version tagging of the Serverless Collection.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions