Skip to content
v2.278.0

PolicyDocumentProps Struct ​

Properties for a new PolicyDocument.

Example ​

ts
const topic = new sns.Topic(this, 'Topic');
const policyDocument = new iam.PolicyDocument({
  assignSids: true,
  statements: [
    new iam.PolicyStatement({
      actions: ["sns:Publish"],
      principals: [new iam.ServicePrincipal('s3.amazonaws.com')],
      resources: [topic.topicArn],
    }),
  ],
});

const topicPolicy = new sns.TopicPolicy(this, 'Policy', {
  topics: [topic],
  policyDocument,
  enforceSSL: true,
});
python
topic = sns.Topic(self, "Topic")
policy_document = iam.PolicyDocument(
    assign_sids=True,
    statements=[
        iam.PolicyStatement(
            actions=["sns:Publish"],
            principals=[iam.ServicePrincipal("s3.amazonaws.com")],
            resources=[topic.topic_arn]
        )
    ]
)

topic_policy = sns.TopicPolicy(self, "Policy",
    topics=[topic],
    policy_document=policy_document,
    enforce_ssl=True
)
java
Topic topic = new Topic(this, "Topic");
PolicyDocument policyDocument = PolicyDocument.Builder.create()
        .assignSids(true)
        .statements(List.of(
            PolicyStatement.Builder.create()
                    .actions(List.of("sns:Publish"))
                    .principals(List.of(new ServicePrincipal("s3.amazonaws.com")))
                    .resources(List.of(topic.getTopicArn()))
                    .build()))
        .build();

TopicPolicy topicPolicy = TopicPolicy.Builder.create(this, "Policy")
        .topics(List.of(topic))
        .policyDocument(policyDocument)
        .enforceSSL(true)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var topic = new Topic(this, "Topic");
var policyDocument = new PolicyDocument(new PolicyDocumentProps {
    AssignSids = true,
    Statements = new [] {
        new PolicyStatement(new PolicyStatementProps {
            Actions = new [] { "sns:Publish" },
            Principals = new [] { new ServicePrincipal("s3.amazonaws.com") },
            Resources = new [] { topic.TopicArn }
        }) }
});

var topicPolicy = new TopicPolicy(this, "Policy", new TopicPolicyProps {
    Topics = new [] { topic },
    PolicyDocument = policyDocument,
    EnforceSSL = true
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
topic := sns.NewTopic(this, jsii.String("Topic"))
policyDocument := iam.NewPolicyDocument(&PolicyDocumentProps{
	AssignSids: jsii.Boolean(true),
	Statements: []PolicyStatement{
		iam.NewPolicyStatement(&PolicyStatementProps{
			Actions: []*string{
				jsii.String("sns:Publish"),
			},
			Principals: []IPrincipal{
				iam.NewServicePrincipal(jsii.String("s3.amazonaws.com")),
			},
			Resources: []*string{
				topic.topicArn,
			},
		}),
	},
})

topicPolicy := sns.NewTopicPolicy(this, jsii.String("Policy"), &TopicPolicyProps{
	Topics: []ITopic{
		topic,
	},
	PolicyDocument: PolicyDocument,
	EnforceSSL: jsii.Boolean(true),
})

Properties ​

assignSidsoptionalbooleanassign_sidsoptionalboolassignSidsoptionalBooleanAssignSidsoptionalboolAssignSidsoptional*bool = false #
Automatically assign Statement Ids to all statements.
minimizeoptionalbooleanminimizeoptionalboolminimizeoptionalBooleanMinimizeoptionalboolMinimizeoptional*bool #
Try to minimize the policy by merging statements.

Default: false, unless the feature flag @aws-cdk/aws-iam:minimizePolicies is set

notes

To avoid overrunning the maximum policy size, combine statements if they produce the same result. Merging happens according to the following rules:

  • The Effect of both statements is the same
  • Neither of the statements have a 'Sid'
  • Combine Principals if the rest of the statement is exactly the same.
  • Combine Resources if the rest of the statement is exactly the same.
  • Combine Actions if the rest of the statement is exactly the same.
  • We will never combine NotPrincipals, NotResources or NotActions, because doing so would change the meaning of the policy document.
statementsoptionalPolicyStatement[]statementsoptionaltyping.List[PolicyStatement]statementsoptionalList<PolicyStatement>StatementsoptionalPolicyStatement[]Statementsoptional*[]PolicyStatement #
Initial statements to add to the policy document.

Default: No statements