aws-cdk-lib.aws_iam.IRole

interface IRole

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

Implemented by LazyRole, Role

Obtainable from TaskDefinition.obtainExecutionRole(), Role.fromRoleArn(), Role.fromRoleName(), Role.withoutPolicyUpdates(), Portfolio.setLocalLaunchRoleName()

A Role object.

Properties

NameTypeDescription
assumeRoleActionstringWhen this Principal is used in an AssumeRole policy, the action to use.
envResourceEnvironmentThe environment this resource belongs to.
grantPrincipalIPrincipalThe principal to grant permissions to.
nodeNodeThe tree node.
policyFragmentPrincipalPolicyFragmentReturn the policy fragment that identifies this principal in a Policy.
roleArnstringReturns the ARN of this role.
roleNamestringReturns the name of this role.
stackStackThe stack in which this resource is defined.
principalAccount?stringThe AWS account ID of this principal.

assumeRoleAction

Type: string

When this Principal is used in an AssumeRole policy, the action to use.


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


grantPrincipal

Type: IPrincipal

The principal to grant permissions to.


node

Type: Node

The tree node.


policyFragment

Type: PrincipalPolicyFragment

Return the policy fragment that identifies this principal in a Policy.


roleArn

Type: string

Returns the ARN of this role.


roleName

Type: string

Returns the name of this role.


stack

Type: Stack

The stack in which this resource is defined.


principalAccount?

Type: string (optional)

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.

Methods

NameDescription
addManagedPolicy(policy)Attaches a managed policy to this principal.
addToPrincipalPolicy(statement)Add to the policy of this principal.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
attachInlinePolicy(policy)Attaches an inline policy to this principal.
grant(grantee, ...actions)Grant the actions defined in actions to the identity Principal on this resource.
grantAssumeRole(grantee)Grant permissions to the given principal to assume this role.
grantPassRole(grantee)Grant permissions to the given principal to pass this role.

addManagedPolicy(policy)

public addManagedPolicy(policy: IManagedPolicy): void

Parameters

  • policy IManagedPolicy — The managed policy.

Attaches a managed policy to this principal.


addToPrincipalPolicy(statement)

public addToPrincipalPolicy(statement: PolicyStatement): AddToPrincipalPolicyResult

Parameters

  • statement PolicyStatement

Returns

  • AddToPrincipalPolicyResult

Add to the policy of this principal.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


attachInlinePolicy(policy)

public attachInlinePolicy(policy: Policy): void

Parameters

  • policy Policy — The policy resource to attach to this principal [disable-awslint:ref-via-interface].

Attaches an inline policy to this principal.

This is the same as calling policy.addToXxx(principal).


grant(grantee, ...actions)

public grant(grantee: IPrincipal, ...actions: string[]): Grant

Parameters

  • grantee IPrincipal
  • actions string

Returns

  • Grant

Grant the actions defined in actions to the identity Principal on this resource.


grantAssumeRole(grantee)

public grantAssumeRole(grantee: IPrincipal): Grant

Parameters

  • grantee IPrincipal

Returns

  • Grant

Grant permissions to the given principal to assume this role.


grantPassRole(grantee)

public grantPassRole(grantee: IPrincipal): Grant

Parameters

  • grantee IPrincipal

Returns

  • Grant

Grant permissions to the given principal to pass this role.