# PolicyProps

Properties for defining an IAM inline policy document.

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

- Source: [`aws-iam/lib/policy.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-iam/lib/policy.ts#L38)

## Example

TypeScript:

```ts
declare const books: apigateway.Resource;
declare const iamUser: iam.User;

const getBooks = books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizationType: apigateway.AuthorizationType.IAM
});

iamUser.attachInlinePolicy(new iam.Policy(this, 'AllowBooks', {
  statements: [
    new iam.PolicyStatement({
      actions: [ 'execute-api:Invoke' ],
      effect: iam.Effect.ALLOW,
      resources: [ getBooks.methodArn ]
    })
  ]
}))
```

Python:

```python
# books: apigateway.Resource
# iam_user: iam.User

get_books = books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorization_type=apigateway.AuthorizationType.IAM
)

iam_user.attach_inline_policy(iam.Policy(self, "AllowBooks",
    statements=[
        iam.PolicyStatement(
            actions=["execute-api:Invoke"],
            effect=iam.Effect.ALLOW,
            resources=[get_books.method_arn]
        )
    ]
))
```

Java:

```java
Resource books;
User iamUser;

Method getBooks = books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizationType(AuthorizationType.IAM)
        .build());

iamUser.attachInlinePolicy(Policy.Builder.create(this, "AllowBooks")
        .statements(List.of(
            PolicyStatement.Builder.create()
                    .actions(List.of("execute-api:Invoke"))
                    .effect(Effect.ALLOW)
                    .resources(List.of(getBooks.getMethodArn()))
                    .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Resource books;
User iamUser;

var getBooks = books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    AuthorizationType = AuthorizationType.IAM
});

iamUser.AttachInlinePolicy(new Policy(this, "AllowBooks", new PolicyProps {
    Statements = new [] {
        new PolicyStatement(new PolicyStatementProps {
            Actions = new [] { "execute-api:Invoke" },
            Effect = Effect.ALLOW,
            Resources = new [] { getBooks.MethodArn }
        }) }
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var books Resource
var iamUser User

getBooks := books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	AuthorizationType: apigateway.AuthorizationType_IAM,
})

iamUser.AttachInlinePolicy(iam.NewPolicy(this, jsii.String("AllowBooks"), &PolicyProps{
	Statements: []PolicyStatement{
		iam.NewPolicyStatement(&PolicyStatementProps{
			Actions: []*string{
				jsii.String("execute-api:Invoke"),
			},
			Effect: iam.Effect_ALLOW,
			Resources: []*string{
				getBooks.methodArn,
			},
		}),
	},
}))
```

## Properties

- `document`: [PolicyDocument](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyDocument.html) — Initial PolicyDocument to use for this Policy.

  **Default:** An empty policy.

  If omited, any
  `PolicyStatement` provided in the `statements` property will be applied
  against the empty default `PolicyDocument`.

- `force`: boolean = false — Force creation of an `AWS::IAM::Policy`.

  Unless set to `true`, this `Policy` construct will not materialize to an
  `AWS::IAM::Policy` CloudFormation resource in case it would have no effect
  (for example, if it remains unattached to an IAM identity or if it has no
  statements). This is generally desired behavior, since it prevents
  creating invalid--and hence undeployable--CloudFormation templates.

  In cases where you know the policy must be created and it is actually
  an error if no statements have been added to it or it remains unattached to
  an IAM identity, you can set this to `true`.

- `groups`: [IGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGroup.html)[] — Groups to attach this policy to.

  **Default:** No groups.

  You can also use `attachToGroup(group)` to attach this policy to a group.

- `policyName`: string — The name of the policy.

  **Default:** Uses the logical ID of the policy resource, which is ensured to be unique within the stack.

  If you specify multiple policies for an entity,
  specify unique names. For example, if you specify a list of policies for
  an IAM role, each policy must have a unique name.

- `roles`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html)[] — Roles to attach this policy to.

  **Default:** No roles.

  You can also use `attachToRole(role)` to attach this policy to a role.

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

  **Default:** No statements.

  You can also use `addStatements(...statement)` to add permissions later.

- `users`: [IUser](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IUser.html)[] — Users to attach this policy to.

  **Default:** No users.

  You can also use `attachToUser(user)` to attach this policy to a user.
