User guide

// using Amazon.IdentityManagement;
// using Amazon.IdentityManagement.Model;
var client = new AmazonIdentityManagementServiceClient();
var request = new CreateInstanceProfileRequest
{
InstanceProfileName = "DemoEC2-InstanceProfile"
};
try
{
client.CreateInstanceProfile(request);
}
catch (EntityAlreadyExistsException)
{
Console.WriteLine(
"The instance profile 'DemoEC2-InstanceProfile' already exists.");
}
Attach an Instance Profile to a Role
The following example attaches an instance profile to a role.
The following example doesn't use the AWS Resource APIs for .NET, as the resource APIs currently
don't support attaching an instance profile to a role. However, this example is presented for completeness:
// using Amazon.IdentityManagement;
// using Amazon.IdentityManagement.Model;
var client = new AmazonIdentityManagementServiceClient();
var request = new AddRoleToInstanceProfileRequest
{
RoleName = "DemoEC2",
InstanceProfileName = "DemoEC2-InstanceProfile"
};
try
{
client.AddRoleToInstanceProfile(request);
}
catch (NoSuchEntityException)
{
Console.WriteLine(
"The role 'DemoEC2' or the instance profile " +
"'DemoEC2-InstanceProfile' does not exist.");
}
catch (LimitExceededException)
{
Console.WriteLine("The role 'DemoEC2' already has " +
"an instance profile attached.");
}
Version v2.0.0
107
AWS SDK for .NET Developer Guide
IAM Resource API Examples