InstanceProfileProps Struct
Properties of an Instance Profile.
| Source | aws-iam/lib/instance-profile.ts |
|---|---|
| Type last changed |
Example
ts
declare const vpc: ec2.Vpc;
const role = new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
});
const instanceProfile = new iam.InstanceProfile(this, 'InstanceProfile', {
role,
});
const template = new ec2.LaunchTemplate(this, 'LaunchTemplate', {
launchTemplateName: 'MyTemplateV1',
versionDescription: 'This is my v1 template',
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
securityGroup: new ec2.SecurityGroup(this, 'LaunchTemplateSG', {
vpc: vpc,
}),
instanceProfile,
});
python
# vpc: ec2.Vpc
role = iam.Role(self, "Role",
assumed_by=iam.ServicePrincipal("ec2.amazonaws.com")
)
instance_profile = iam.InstanceProfile(self, "InstanceProfile",
role=role
)
template = ec2.LaunchTemplate(self, "LaunchTemplate",
launch_template_name="MyTemplateV1",
version_description="This is my v1 template",
machine_image=ec2.MachineImage.latest_amazon_linux2023(),
security_group=ec2.SecurityGroup(self, "LaunchTemplateSG",
vpc=vpc
),
instance_profile=instance_profile
)
java
Vpc vpc;
Role role = Role.Builder.create(this, "Role")
.assumedBy(new ServicePrincipal("ec2.amazonaws.com"))
.build();
InstanceProfile instanceProfile = InstanceProfile.Builder.create(this, "InstanceProfile")
.role(role)
.build();
LaunchTemplate template = LaunchTemplate.Builder.create(this, "LaunchTemplate")
.launchTemplateName("MyTemplateV1")
.versionDescription("This is my v1 template")
.machineImage(MachineImage.latestAmazonLinux2023())
.securityGroup(SecurityGroup.Builder.create(this, "LaunchTemplateSG")
.vpc(vpc)
.build())
.instanceProfile(instanceProfile)
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
var role = new Role(this, "Role", new RoleProps {
AssumedBy = new ServicePrincipal("ec2.amazonaws.com")
});
var instanceProfile = new InstanceProfile(this, "InstanceProfile", new InstanceProfileProps {
Role = role
});
var template = new LaunchTemplate(this, "LaunchTemplate", new LaunchTemplateProps {
LaunchTemplateName = "MyTemplateV1",
VersionDescription = "This is my v1 template",
MachineImage = MachineImage.LatestAmazonLinux2023(),
SecurityGroup = new SecurityGroup(this, "LaunchTemplateSG", new SecurityGroupProps {
Vpc = vpc
}),
InstanceProfile = instanceProfile
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
role := iam.NewRole(this, jsii.String("Role"), &RoleProps{
AssumedBy: iam.NewServicePrincipal(jsii.String("ec2.amazonaws.com")),
})
instanceProfile := iam.NewInstanceProfile(this, jsii.String("InstanceProfile"), &InstanceProfileProps{
Role: Role,
})
template := ec2.NewLaunchTemplate(this, jsii.String("LaunchTemplate"), &LaunchTemplateProps{
LaunchTemplateName: jsii.String("MyTemplateV1"),
VersionDescription: jsii.String("This is my v1 template"),
MachineImage: ec2.MachineImage_LatestAmazonLinux2023(),
SecurityGroup: ec2.NewSecurityGroup(this, jsii.String("LaunchTemplateSG"), &SecurityGroupProps{
Vpc: vpc,
}),
InstanceProfile: InstanceProfile,
})
Properties
instanceProfileNameoptionalstringinstance_profile_nameoptionalstrinstanceProfileNameoptionalStringInstanceProfileNameoptionalstringInstanceProfileNameoptional*string #The name of the InstanceProfile to create.
Default: generated by CloudFormation
The path to the InstanceProfile.
An IAM role to associate with the instance profile that is used by EC2 instances.
Default: a role will be automatically created, it can be accessed via the role property
The role must be assumable by the service principal ec2.amazonaws.com:
example
ts
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});