interface IRole
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.IAM.IRole |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsiam#IRole |
Java | software.amazon.awscdk.services.iam.IRole |
Python | aws_cdk.aws_iam.IRole |
TypeScript (source) | aws-cdk-lib » aws_iam » IRole |
Obtainable from
Task
.obtainExecutionRole()
, Role
.fromRoleArn()
, Role
.fromRoleName()
, Role
.withoutPolicyUpdates()
, Portfolio
.setLocalLaunchRoleName()
A Role object.
Properties
Name | Type | Description |
---|---|---|
assume | string | When this Principal is used in an AssumeRole policy, the action to use. |
env | Resource | The environment this resource belongs to. |
grant | IPrincipal | The principal to grant permissions to. |
node | Node | The tree node. |
policy | Principal | Return the policy fragment that identifies this principal in a Policy. |
role | string | Returns the ARN of this role. |
role | string | Returns the name of this role. |
stack | Stack | The stack in which this resource is defined. |
principal | string | The AWS account ID of this principal. |
assumeRoleAction
Type:
string
When this Principal is used in an AssumeRole policy, the action to use.
env
Type:
Resource
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:
Principal
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
Name | Description |
---|---|
add | Attaches a managed policy to this principal. |
add | Add to the policy of this principal. |
apply | Apply the given removal policy to this resource. |
attach | Attaches an inline policy to this principal. |
grant(grantee, ...actions) | Grant the actions defined in actions to the identity Principal on this resource. |
grant | Grant permissions to the given principal to assume this role. |
grant | Grant permissions to the given principal to pass this role. |
ManagedPolicy(policy)
addpublic addManagedPolicy(policy: IManagedPolicy): void
Parameters
- policy
IManaged
— The managed policy.Policy
Attaches a managed policy to this principal.
ToPrincipalPolicy(statement)
addpublic addToPrincipalPolicy(statement: PolicyStatement): AddToPrincipalPolicyResult
Parameters
- statement
Policy
Statement
Returns
Add to the policy of this principal.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
).
InlinePolicy(policy)
attachpublic 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 the actions defined in actions to the identity Principal on this resource.
AssumeRole(grantee)
grantpublic grantAssumeRole(grantee: IPrincipal): Grant
Parameters
- grantee
IPrincipal
Returns
Grant permissions to the given principal to assume this role.
PassRole(grantee)
grantpublic grantPassRole(grantee: IPrincipal): Grant
Parameters
- grantee
IPrincipal
Returns
Grant permissions to the given principal to pass this role.