Skip to content
v2.274.0

PolicyProps Struct ​

Properties for defining an IAM inline policy document.

Example ​

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

Properties ​

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.

forcebooleanforceboolforceBooleanForceboolForce*bool= false#
Force creation of an `AWS::IAM::Policy`.
notes

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.

groupsIGroup[]groupstyping.List[IGroup]groupsList<IGroup>GroupsIGroup[]Groups*[]IGroup#
Groups to attach this policy to.

Default: No groups.

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

policyNamestringpolicy_namestrpolicyNameStringPolicyNamestringPolicyName*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.

rolesIRole[]rolestyping.List[IRole]rolesList<IRole>RolesIRole[]Roles*[]IRole#
Roles to attach this policy to.

Default: No roles.

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

statementsPolicyStatement[]statementstyping.List[PolicyStatement]statementsList<PolicyStatement>StatementsPolicyStatement[]Statements*[]PolicyStatement#
Initial set of permissions to add to this policy document.

Default: No statements.

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

usersIUser[]userstyping.List[IUser]usersList<IUser>UsersIUser[]Users*[]IUser#
Users to attach this policy to.

Default: No users.

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