java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
All Implemented Interfaces:
IConstruct, IDependable, IResource, IGrantable, IIdentity, IPrincipal, IRole, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:57.366Z") @Stability(Stable) public class Role extends Resource implements IRole
IAM Role.

Defines an IAM role. The role is created with an assume policy document associated with the specified AWS service principal defined in serviceAssumeRole.

Example:

 Role lambdaRole = Role.Builder.create(this, "Role")
         .assumedBy(new ServicePrincipal("lambda.amazonaws.com"))
         .description("Example role...")
         .build();
 Stream stream = Stream.Builder.create(this, "MyEncryptedStream")
         .encryption(StreamEncryption.KMS)
         .build();
 // give lambda permissions to read stream
 stream.grantRead(lambdaRole);
 
  • Constructor Details

    • Role

      protected Role(software.amazon.jsii.JsiiObjectRef objRef)
    • Role

      protected Role(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Role

      @Stability(Stable) public Role(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull RoleProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromRoleArn

      @Stability(Stable) @NotNull public static IRole fromRoleArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String roleArn, @Nullable FromRoleArnOptions options)
      Import an external role by ARN.

      If the imported Role ARN is a Token (such as a CfnParameter.valueAsString or a Fn.importValue()) and the referenced role has a path (like arn:...:role/AdminRoles/Alice), the roleName property will not resolve to the correct value. Instead it will resolve to the first path component. We unfortunately cannot express the correct calculation of the full path name as a CloudFormation expression. In this scenario the Role ARN should be supplied without the path in order to resolve the correct role resource.

      Parameters:
      scope - construct scope. This parameter is required.
      id - construct id. This parameter is required.
      roleArn - the ARN of the role to import. This parameter is required.
      options - allow customizing the behavior of the returned role.
    • fromRoleArn

      @Stability(Stable) @NotNull public static IRole fromRoleArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String roleArn)
      Import an external role by ARN.

      If the imported Role ARN is a Token (such as a CfnParameter.valueAsString or a Fn.importValue()) and the referenced role has a path (like arn:...:role/AdminRoles/Alice), the roleName property will not resolve to the correct value. Instead it will resolve to the first path component. We unfortunately cannot express the correct calculation of the full path name as a CloudFormation expression. In this scenario the Role ARN should be supplied without the path in order to resolve the correct role resource.

      Parameters:
      scope - construct scope. This parameter is required.
      id - construct id. This parameter is required.
      roleArn - the ARN of the role to import. This parameter is required.
    • fromRoleName

      @Stability(Stable) @NotNull public static IRole fromRoleName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String roleName)
      Import an external role by name.

      The imported role is assumed to exist in the same account as the account the scope's containing Stack is being deployed to.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      roleName - This parameter is required.
    • addManagedPolicy

      @Stability(Stable) public void addManagedPolicy(@NotNull IManagedPolicy policy)
      Attaches a managed policy to this role.

      Specified by:
      addManagedPolicy in interface IIdentity
      Parameters:
      policy - The the managed policy to attach. This parameter is required.
    • addToPolicy

      @Stability(Stable) @NotNull public Boolean addToPolicy(@NotNull PolicyStatement statement)
      Add to the policy of this principal.

      Specified by:
      addToPolicy in interface IPrincipal
      Parameters:
      statement - This parameter is required.
      Returns:
      true if the statement was added, false if the principal in question does not have a policy document to add the statement to.
    • addToPrincipalPolicy

      @Stability(Stable) @NotNull public AddToPrincipalPolicyResult addToPrincipalPolicy(@NotNull PolicyStatement statement)
      Adds a permission to the role's default policy document.

      If there is no default policy attached to this role, it will be created.

      Specified by:
      addToPrincipalPolicy in interface IPrincipal
      Parameters:
      statement - The permission statement to add to the policy document. This parameter is required.
    • attachInlinePolicy

      @Stability(Stable) public void attachInlinePolicy(@NotNull Policy policy)
      Attaches a policy to this role.

      Specified by:
      attachInlinePolicy in interface IIdentity
      Parameters:
      policy - The policy to attach. This parameter is required.
    • grant

      @Stability(Stable) @NotNull public Grant grant(@NotNull IPrincipal grantee, @NotNull @NotNull String... actions)
      Grant the actions defined in actions to the identity Principal on this resource.

      Specified by:
      grant in interface IRole
      Parameters:
      grantee - This parameter is required.
      actions - This parameter is required.
    • grantAssumeRole

      @Stability(Stable) @NotNull public Grant grantAssumeRole(@NotNull IPrincipal identity)
      Grant permissions to the given principal to assume this role.

      Specified by:
      grantAssumeRole in interface IRole
      Parameters:
      identity - This parameter is required.
    • grantPassRole

      @Stability(Stable) @NotNull public Grant grantPassRole(@NotNull IPrincipal identity)
      Grant permissions to the given principal to pass this role.

      Specified by:
      grantPassRole in interface IRole
      Parameters:
      identity - This parameter is required.
    • validate

      @Stability(Stable) @NotNull protected List<String> validate()
      Validate the current construct.

      This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.

      Overrides:
      validate in class Construct
      Returns:
      An array of validation error messages, or an empty array if the construct is valid.
    • withoutPolicyUpdates

      @Stability(Stable) @NotNull public IRole withoutPolicyUpdates(@Nullable WithoutPolicyUpdatesOptions options)
      Return a copy of this Role object whose Policies will not be updated.

      Use the object returned by this method if you want this Role to be used by a construct without it automatically updating the Role's Policies.

      If you do, you are responsible for adding the correct statements to the Role's policies yourself.

      Parameters:
      options -
    • withoutPolicyUpdates

      @Stability(Stable) @NotNull public IRole withoutPolicyUpdates()
      Return a copy of this Role object whose Policies will not be updated.

      Use the object returned by this method if you want this Role to be used by a construct without it automatically updating the Role's Policies.

      If you do, you are responsible for adding the correct statements to the Role's policies yourself.

    • getAssumeRoleAction

      @Stability(Stable) @NotNull public String getAssumeRoleAction()
      When this Principal is used in an AssumeRole policy, the action to use.
      Specified by:
      getAssumeRoleAction in interface IPrincipal
    • getGrantPrincipal

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The principal to grant permissions to.
      Specified by:
      getGrantPrincipal in interface IGrantable
    • getPolicyFragment

      @Stability(Stable) @NotNull public PrincipalPolicyFragment getPolicyFragment()
      Returns the role.
      Specified by:
      getPolicyFragment in interface IPrincipal
    • getRoleArn

      @Stability(Stable) @NotNull public String getRoleArn()
      Returns the ARN of this role.
      Specified by:
      getRoleArn in interface IRole
    • getRoleId

      @Stability(Stable) @NotNull public String getRoleId()
      Returns the stable and unique string identifying the role.

      For example, AIDAJQABLZS4A3QDU576Q.

    • getRoleName

      @Stability(Stable) @NotNull public String getRoleName()
      Returns the name of the role.
      Specified by:
      getRoleName in interface IRole
    • getAssumeRolePolicy

      @Stability(Stable) @Nullable public PolicyDocument getAssumeRolePolicy()
      The assume role policy document associated with this role.
    • getPermissionsBoundary

      @Stability(Stable) @Nullable public IManagedPolicy getPermissionsBoundary()
      Returns the permissions boundary attached to this role.
    • getPrincipalAccount

      @Stability(Stable) @Nullable public String getPrincipalAccount()
      The AWS account ID of this principal.

      Can be undefined when the account is not known (for example, for service principals). Can be a Token - in that case, it's assumed to be AWS::AccountId.

      Specified by:
      getPrincipalAccount in interface IPrincipal