Skip to content

(sns): default .fifo suffix for FIFO topics #18740

@skyrpex

Description

@skyrpex

Description

#12386 introduced a requirement to add a topic name whenever a FIFO topic is created.

Do you think it's a good idea to generate a default name if it isn't provided by the user? All of the other CDK resources are named consistently using something similar to what cdk.Names.nodeUniqueId(node) does, ie MyStack2EC66409Topic.fifo, which prevents name collisions.

Use Case

Remove the need to manually define a topic name.

Proposed Solution

This is my current implementation:

import * as cdk from "aws-cdk-lib"
import { Construct, Node } from "constructs"

export class Topic extends cdk.aws_sns.Topic {
  public constructor(
    scope: Construct,
    id: string,
    properties?: cdk.aws_sns.TopicProps,
  ) {
    super(scope, id, {
      ...properties,
      topicName:
        properties?.topicName ?? properties?.fifo
          ? buildFifoName(scope.node, id)
          : undefined,
    })
  }
}

export function buildFifoName(node: Node, id: string) {
  const uniqueId = cdk.Names.nodeUniqueId(node)
  const suffix = `${id}.fifo`
  // Make sure that the name fits within the CFN's 80 character limit
  return `${uniqueId.slice(0, Math.max(0, 80 - suffix.length))}${suffix}`
}

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Metadata

Metadata

Labels

@aws-cdk/aws-snsRelated to Amazon Simple Notification Serviceeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.feature/enhancementA new API to make things easier or more intuitive. A catch-all for general feature requests.good first issueRelated to contributions. See CONTRIBUTING.mdp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions