Class Policy
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.iam.Policy
- All Implemented Interfaces:
IPolicyRef,IEnvironmentAware,IResource,IGrantable,IPolicy,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.119.0 (build 1634eac)",
date="2025-11-20T23:37:23.005Z")
@Stability(Stable)
public class Policy
extends Resource
implements IPolicy, IGrantable
The AWS::IAM::Policy resource associates an inline IAM policy with IAM users, roles, or groups. For more information about IAM policies, see Overview of IAM Policies in the IAM User Guide guide.
Example:
Function postAuthFn;
UserPool userpool = UserPool.Builder.create(this, "myuserpool")
.lambdaTriggers(UserPoolTriggers.builder()
.postAuthentication(postAuthFn)
.build())
.build();
// provide permissions to describe the user pool scoped to the ARN the user pool
postAuthFn.role.attachInlinePolicy(Policy.Builder.create(this, "userpool-policy")
.statements(List.of(PolicyStatement.Builder.create()
.actions(List.of("cognito-idp:DescribeUserPool"))
.resources(List.of(userpool.getUserPoolArn()))
.build()))
.build());
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.iam.IGrantable
IGrantable.Jsii$Default, IGrantable.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.services.iam.IPolicy
IPolicy.Jsii$Default, IPolicy.Jsii$ProxyNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedPolicy(software.amazon.jsii.JsiiObjectRef objRef) Policy(software.constructs.Construct scope, String id, PolicyProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStatements(PolicyStatement... statement) Adds a statement to the policy document.voidattachToGroup(IGroup group) Attaches this policy to a group.voidattachToRole(IRole role) Attaches this policy to a role.voidattachToUser(IUser user) Attaches this policy to a user.static IPolicyfromPolicyName(software.constructs.Construct scope, String id, String policyName) Import a policy in this app based on its name.The policy document.The principal to grant permissions to.The name of this policy.A reference to a Policy resource.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
Constructor Details
-
Policy
protected Policy(software.amazon.jsii.JsiiObjectRef objRef) -
Policy
protected Policy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
Policy
@Stability(Stable) public Policy(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable PolicyProps props) - Parameters:
scope- This parameter is required.id- This parameter is required.props-
-
Policy
- Parameters:
scope- This parameter is required.id- This parameter is required.
-
-
Method Details
-
fromPolicyName
@Stability(Stable) @NotNull public static IPolicy fromPolicyName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String policyName) Import a policy in this app based on its name.- Parameters:
scope- This parameter is required.id- This parameter is required.policyName- This parameter is required.
-
addStatements
Adds a statement to the policy document.- Parameters:
statement- This parameter is required.
-
attachToGroup
Attaches this policy to a group.- Parameters:
group- This parameter is required.
-
attachToRole
Attaches this policy to a role.- Parameters:
role- This parameter is required.
-
attachToUser
Attaches this policy to a user.- Parameters:
user- This parameter is required.
-
getDocument
The policy document. -
getGrantPrincipal
The principal to grant permissions to.- Specified by:
getGrantPrincipalin interfaceIGrantable
-
getPolicyName
The name of this policy.- Specified by:
getPolicyNamein interfaceIPolicy
-
getPolicyRef
A reference to a Policy resource.- Specified by:
getPolicyRefin interfaceIPolicyRef
-