aws-cdk-lib.aws_iam.PolicyProps

interface PolicyProps

LanguageType name
.NETAmazon.CDK.AWS.IAM.PolicyProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsiam#PolicyProps
Javasoftware.amazon.awscdk.services.iam.PolicyProps
Pythonaws_cdk.aws_iam.PolicyProps
TypeScript (source)aws-cdk-lib » aws_iam » PolicyProps

Properties for defining an IAM inline policy document.

Example

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 ]
    })
  ]
}))

Properties

NameTypeDescription
document?PolicyDocumentInitial PolicyDocument to use for this Policy.
force?booleanForce creation of an AWS::IAM::Policy.
groups?IGroup[]Groups to attach this policy to.
policyName?stringThe name of the policy.
roles?IRole[]Roles to attach this policy to.
statements?PolicyStatement[]Initial set of permissions to add to this policy document.
users?IUser[]Users to attach this policy to.

document?

Type: PolicyDocument (optional, default: An empty policy.)

Initial PolicyDocument to use for this Policy.

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


force?

Type: boolean (optional, default: 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, you can set this to true.


groups?

Type: IGroup[] (optional, default: No groups.)

Groups to attach this policy to.

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


policyName?

Type: string (optional, default: Uses the logical ID of the policy resource, which is ensured to be unique within the stack.)

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.


roles?

Type: IRole[] (optional, default: No roles.)

Roles to attach this policy to.

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


statements?

Type: PolicyStatement[] (optional, default: No statements.)

Initial set of permissions to add to this policy document.

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


users?

Type: IUser[] (optional, default: No users.)

Users to attach this policy to.

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