Amazon AWS SDK Podręcznik Użytkownika Strona 111: Attach an Instance Profile to a Role

/ 155
Spis treści
// 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

Plik PDF · ·

Drukuj

Drukuj dokument

Dzielenie się

Pytania o Amazon AWS SDK

Nie ma jeszcze pytań o tę instrukcję. Zadaj pierwsze.

Zadaj pytanie

Odpowiadamy na podstawie instrukcji i wskazujemy stronę. Pytanie pojawi się w serwisie po sprawdzeniu.

Wszystkie pytania i odpowiedzi ›

Powiązane produkty i podręczniki dla Oprogramowanie Amazon AWS SDK