aws-cdk-lib.aws_iam.IIdentity

interface IIdentity

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

Implemented by Group, LazyRole, Role, User

A construct that represents an IAM principal, such as a user, group or role.

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


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.

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).