# PolicyDocumentProps

Properties for a new PolicyDocument.

Used as props by: [PolicyDocument](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyDocument.html)

- Source: [`aws-iam/lib/policy-document.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-iam/lib/policy-document.ts#L13)
- Type last changed: v2.18.0 · 29 Mar 2022

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
});
```

Golang:

```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

- `assignSids`: boolean = false — Automatically assign Statement Ids to all statements.

- `minimize`: boolean — Try to minimize the policy by merging statements.

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

  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.

- `statements`: [PolicyStatement](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyStatement.html)[] — Initial statements to add to the policy document.

  **Default:** No statements
