Skip to content

Fix OpenSearch Serverless Collection Tagging Without Replacement #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: feature/cost-tagging
Choose a base branch
from

Conversation

wadabee
Copy link
Contributor

@wadabee wadabee commented Jul 9, 2025

Problem

When adding cost management tags to OpenSearch Serverless Collection, CloudFormation fails with the error:

CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename 3hf17j1yj99d59m78e0k and update the stack again.

This occurs because CloudFormation attempts to replace the existing resource when adding tags directly to the CfnCollection construct.

Solution

This PR implements a solution that adds tags to OpenSearch Serverless Collection using a separate Custom Resource instead of directly adding tags to the collection definition. This approach avoids the CloudFormation replacement error by:

  1. Creating the collection without tags in the CloudFormation template
  2. Using a dedicated Custom Resource to apply tags via AWS SDK after the collection is created
  3. Ensuring proper dependency chain so tags are applied after collection creation

Implementation Details

  • Added a new apply-tags.js custom resource handler that uses the AWS SDK to apply tags
  • Modified the RagKnowledgeBaseStack to create collections without tags and use the custom resource for tagging
  • Added appropriate IAM permissions for the tag application Lambda function

Benefits

  • Allows adding cost management tags without replacing existing collections
  • Preserves all existing OpenSearch indexes and data
  • No service disruption during tag updates

Impact on Existing Data

  • This implementation has no impact on existing OpenSearch indexes or documents
  • Tagging happens at the collection metadata level only
  • No index recreation or data modification occurs

Open in Web UI: https://d2l9xhci5nmbbp.cloudfront.net/sessions/1751969257116919

@wadabee wadabee changed the base branch from main to feature/cost-tagging July 9, 2025 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant