# InstanceProfileProps

Properties of an Instance Profile.

Used as props by: [InstanceProfile](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.InstanceProfile.html)

- Source: [`aws-iam/lib/instance-profile.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-iam/lib/instance-profile.ts#L38)
- Type last changed: v2.88.0 · 20 Jul 2023

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
});
```

Golang:

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

- `instanceProfileName`: string — The name of the InstanceProfile to create.

  **Default:** generated by CloudFormation

- `path`: string = / — The path to the InstanceProfile.

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — 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`:

  ```ts
  const role = new iam.Role(this, 'MyRole', {
    assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
  });
  ```
