AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

Policy

The AWS::IAM::Policy resource associates an [inline](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#inline) IAM policy with IAM users, roles, or groups. For more information about IAM policies, see [Overview of IAM Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/policies_overview.html) in the IAM User Guide guide.

Import

import { Policy } from 'aws-cdk-lib/aws-iam';

Or use the module namespace:

import * as iam from 'aws-cdk-lib/aws-iam';
// iam.Policy

Properties

Configuration passed to the constructor as PolicyProps.

documentOptional
PolicyDocument

Initial PolicyDocument to use for this Policy. If omited, any `PolicyStatement` provided in the `statements` property will be applied against the empty default `PolicyDocument`.

Default: - An empty policy.

forceOptional
boolean

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

Default: false

groupsOptional
IGroup[]

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

Default: - No groups.

policyNameOptional
string

The name of the policy. 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.

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

rolesOptional
IRole[]

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

Default: - No roles.

statementsOptional
PolicyStatement[]

Initial set of permissions to add to this policy document. You can also use `addStatements(...statement)` to add permissions later.

Default: - No statements.

usersOptional
IUser[]

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

Default: - No users.

Get the AWS IAM Cheat Sheet

Everything you need to know about AWS IAM on one page. HD quality, print-friendly.

Download Free Infographic