# PolicyDocument

A PolicyDocument is a collection of statements.

Implements: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html)
Obtainable from: PolicyDocument.fromJson
Used as argument in: [IAssumeRolePrincipal.addToAssumeRolePolicy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IAssumeRolePrincipal.html#addtoassumerolepolicy)

- 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#L50)
- Type last changed: v2.263.0 · 31 Jul 2026

## Example

TypeScript:

```ts
import * as iam from 'aws-cdk-lib/aws-iam';

const myFileSystemPolicy = new iam.PolicyDocument({
  statements: [new iam.PolicyStatement({
    actions: [
      'elasticfilesystem:ClientWrite',
      'elasticfilesystem:ClientMount',
    ],
    principals: [new iam.AccountRootPrincipal()],
    resources: ['*'],
    conditions: {
      Bool: {
        'elasticfilesystem:AccessedViaMountTarget': 'true',
      },
    },
  })],
});

const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
  vpc: new ec2.Vpc(this, 'VPC'),
  fileSystemPolicy: myFileSystemPolicy,
});
```

Python:

```python
import aws_cdk.aws_iam as iam

my_file_system_policy = iam.PolicyDocument(
    statements=[iam.PolicyStatement(
        actions=["elasticfilesystem:ClientWrite", "elasticfilesystem:ClientMount"
        ],
        principals=[iam.AccountRootPrincipal()],
        resources=["*"],
        conditions={
            "Bool": {
                "elasticfilesystem:AccessedViaMountTarget": "true"
            }
        }
    )]
)

file_system = efs.FileSystem(self, "MyEfsFileSystem",
    vpc=ec2.Vpc(self, "VPC"),
    file_system_policy=my_file_system_policy
)
```

Java:

```java
import software.amazon.awscdk.services.iam.*;

PolicyDocument myFileSystemPolicy = PolicyDocument.Builder.create()
        .statements(List.of(PolicyStatement.Builder.create()
                .actions(List.of("elasticfilesystem:ClientWrite", "elasticfilesystem:ClientMount"))
                .principals(List.of(new AccountRootPrincipal()))
                .resources(List.of("*"))
                .conditions(Map.of(
                        "Bool", Map.of(
                                "elasticfilesystem:AccessedViaMountTarget", "true")))
                .build()))
        .build();

FileSystem fileSystem = FileSystem.Builder.create(this, "MyEfsFileSystem")
        .vpc(new Vpc(this, "VPC"))
        .fileSystemPolicy(myFileSystemPolicy)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.IAM;

var myFileSystemPolicy = new PolicyDocument(new PolicyDocumentProps {
    Statements = new [] { new PolicyStatement(new PolicyStatementProps {
        Actions = new [] { "elasticfilesystem:ClientWrite", "elasticfilesystem:ClientMount" },
        Principals = new [] { new AccountRootPrincipal() },
        Resources = new [] { "*" },
        Conditions = new Dictionary<string, object> {
            { "Bool", new Dictionary<string, string> {
                { "elasticfilesystem:AccessedViaMountTarget", "true" }
            } }
        }
    }) }
});

var fileSystem = new FileSystem(this, "MyEfsFileSystem", new FileSystemProps {
    Vpc = new Vpc(this, "VPC"),
    FileSystemPolicy = myFileSystemPolicy
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

myFileSystemPolicy := iam.NewPolicyDocument(&PolicyDocumentProps{
	Statements: []PolicyStatement{
		iam.NewPolicyStatement(&PolicyStatementProps{
			Actions: []*string{
				jsii.String("elasticfilesystem:ClientWrite"),
				jsii.String("elasticfilesystem:ClientMount"),
			},
			Principals: []IPrincipal{
				iam.NewAccountRootPrincipal(),
			},
			Resources: []*string{
				jsii.String("*"),
			},
			Conditions: map[string]interface{}{
				"Bool": map[string]*string{
					"elasticfilesystem:AccessedViaMountTarget": jsii.String("true"),
				},
			},
		}),
	},
})

fileSystem := efs.NewFileSystem(this, jsii.String("MyEfsFileSystem"), &FileSystemProps{
	Vpc: ec2.NewVpc(this, jsii.String("VPC")),
	FileSystemPolicy: myFileSystemPolicy,
})
```

## Initializer

TypeScript:

```ts
new PolicyDocument(props?: PolicyDocumentProps)
```

Python:

```python
PolicyDocument(props: typing.Optional[PolicyDocumentProps] = None)
```

Java:

```java
new PolicyDocument(PolicyDocumentProps props)
```

C# / .NET:

```csharp
new PolicyDocument(PolicyDocumentProps? props = null)
```

Golang:

```go
NewPolicyDocument(Props PolicyDocumentProps)
```

## Properties

- `creationStack`: string[] — The creation stack of this resolvable which will be appended to errors thrown during resolution.

  This may return an array with a single informational element indicating how
  to get this property populated, if it was skipped for performance reasons.

- `isEmpty`: boolean — Whether the policy document contains any statements.

- `statementCount`: number — The number of statements already added to this policy.

  Can be used, for example, to generate unique "sid"s within the policy.

## Methods

- `addStatements(...statement: PolicyStatement[]): void` — Adds a statement to the policy document.

  **Parameters**

  - `statement` — the statement to add.

- `fromJson(obj: any): PolicyDocument // chainable` (static) — Creates a new PolicyDocument based on the object provided.

  This will accept an object created from the `.toJSON()` call

  **Parameters**

  - `obj` — the PolicyDocument in object form.

- `resolve(context: IResolveContext): any` — Produce the Token's value at resolution time.

- `toJSON(): any` — JSON-ify the document.

  Used when JSON.stringify() is called

- `toString(): string` — Encode the policy document as a string.

- `validateForAnyPolicy(): string[]` — Validate that all policy statements in the policy document satisfies the requirements for any policy.

  **Returns:** An array of validation error messages, or an empty array if the document is valid.

- `validateForIdentityPolicy(): string[]` — Validate that all policy statements in the policy document satisfies the requirements for an identity-based policy.

  **Returns:** An array of validation error messages, or an empty array if the document is valid.

- `validateForResourcePolicy(options?: ResourcePolicyValidationOptions): string[]` — Validate that all policy statements in the policy document satisfies the requirements for a resource-based policy.

  **Parameters**

  - `options` — Optional validation options.

  **Returns:** An array of validation error messages, or an empty array if the document is valid.

- `validateForTrustPolicy(): string[]` — Validate that all policy statements in the policy document satisfies the requirements for a trust policy (assume role policy).

  Trust policies are a special type of resource-based policy where the resource is implicit (the role itself).

  **Returns:** An array of validation error messages, or an empty array if the document is valid.
