Class TopicPolicy

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.sns.TopicPolicy
All Implemented Interfaces:
IResource, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-18T17:54:25.071Z") @Stability(Stable) public class TopicPolicy extends Resource
The policy for an SNS Topic.

Policies define the operations that are allowed on this resource.

You almost never need to define this construct directly.

All AWS resources that support resource policies have a method called addToResourcePolicy(), which will automatically create a new resource policy if one doesn't exist yet, otherwise it will add to the existing policy.

Prefer to use addToResourcePolicy() instead.

Example:

 Topic topic = new Topic(this, "Topic");
 PolicyDocument policyDocument = PolicyDocument.Builder.create()
         .assignSids(true)
         .statements(List.of(
             PolicyStatement.Builder.create()
                     .actions(List.of("sns:Subscribe"))
                     .principals(List.of(new AnyPrincipal()))
                     .resources(List.of(topic.getTopicArn()))
                     .build()))
         .build();
 TopicPolicy topicPolicy = TopicPolicy.Builder.create(this, "Policy")
         .topics(List.of(topic))
         .policyDocument(policyDocument)
         .build();
 
  • Constructor Details

    • TopicPolicy

      protected TopicPolicy(software.amazon.jsii.JsiiObjectRef objRef)
    • TopicPolicy

      protected TopicPolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • TopicPolicy

      @Stability(Stable) public TopicPolicy(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull TopicPolicyProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • createSSLPolicyDocument

      @Stability(Stable) @NotNull protected PolicyStatement createSSLPolicyDocument(@NotNull String topicArn)
      Adds a statement to enforce encryption of data in transit when publishing to the topic.

      For more information, see https://docs.aws.amazon.com/sns/latest/dg/sns-security-best-practices.html#enforce-encryption-data-in-transit.

      Parameters:
      topicArn - This parameter is required.
    • getDocument

      @Stability(Stable) @NotNull public PolicyDocument getDocument()
      The IAM policy document for this policy.