class InstanceProfile (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.IAM.InstanceProfile |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsiam#InstanceProfile |
Java | software.amazon.awscdk.services.iam.InstanceProfile |
Python | aws_cdk.aws_iam.InstanceProfile |
TypeScript (source) | aws-cdk-lib » aws_iam » InstanceProfile |
Implements
IConstruct
, IDependable
, IResource
, IInstance
IAM Instance Profile.
Example
const role = new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
});
const instanceProfile = iam.InstanceProfile.fromInstanceProfileAttributes(this, 'ImportedInstanceProfile', {
instanceProfileArn: 'arn:aws:iam::account-id:instance-profile/MyInstanceProfile',
role,
});
Initializer
new InstanceProfile(scope: Construct, id: string, props?: InstanceProfileProps)
Parameters
- scope
Construct
- id
string
- props
Instance
Profile Props
Construct Props
Name | Type | Description |
---|---|---|
instance | string | The name of the InstanceProfile to create. |
path? | string | The path to the InstanceProfile. |
role? | IRole | An IAM role to associate with the instance profile that is used by EC2 instances. |
instanceProfileName?
Type:
string
(optional, default: generated by CloudFormation)
The name of the InstanceProfile to create.
path?
Type:
string
(optional, default: /)
The path to the InstanceProfile.
role?
Type:
IRole
(optional, default: a role will be automatically created, it can be accessed via the role
property)
An IAM role to associate with the instance profile that is used by EC2 instances.
The role must be assumable by the service principal ec2.amazonaws.com
:
Example
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
instance | string | Returns the ARN of this InstanceProfile. |
instance | string | Returns the name of this InstanceProfile. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
role? | IRole | Returns the role associated with this InstanceProfile. |
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.
instanceProfileArn
Type:
string
Returns the ARN of this InstanceProfile.
instanceProfileName
Type:
string
Returns the name of this InstanceProfile.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
role?
Type:
IRole
(optional)
Returns the role associated with this InstanceProfile.
Methods
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Import an existing InstanceProfile from an InstanceProfile ARN. |
static from | Import an existing InstanceProfile from given InstanceProfile attributes. |
static from | Import an existing InstanceProfile from an InstanceProfile name. |
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
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
InstanceProfileArn(scope, id, instanceProfileArn)
static frompublic static fromInstanceProfileArn(scope: Construct, id: string, instanceProfileArn: string): IInstanceProfile
Parameters
- scope
Construct
— construct scope. - id
string
— construct id. - instanceProfileArn
string
— the ARN of the exiting InstanceProfile to import.
Returns
Import an existing InstanceProfile from an InstanceProfile ARN.
If the ARN comes from a Token, the InstanceProfile cannot have a path; if so, any attempt to reference its instanceProfileName will fail.
InstanceProfileAttributes(scope, id, attrs)
static frompublic static fromInstanceProfileAttributes(scope: Construct, id: string, attrs: InstanceProfileAttributes): IInstanceProfile
Parameters
- scope
Construct
— construct scope. - id
string
— construct id. - attrs
Instance
— the attributes of the InstanceProfile to import.Profile Attributes
Returns
Import an existing InstanceProfile from given InstanceProfile attributes.
If the ARN comes from a Token, the InstanceProfile cannot have a path; if so, any attempt to reference its instanceProfileName will fail.
InstanceProfileName(scope, id, instanceProfileName)
static frompublic static fromInstanceProfileName(scope: Construct, id: string, instanceProfileName: string): IInstanceProfile
Parameters
- scope
Construct
— construct scope. - id
string
— construct id. - instanceProfileName
string
— the name of the existing InstanceProfile to import.
Returns
Import an existing InstanceProfile from an InstanceProfile name.