Amazon AWS SDK Guía de usuario Pagina 105

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 155
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 104
}
catch (NoSuchEntityException)
{
Console.WriteLine("Group 'DemoGroup' or " +
"user 'DemoUser' does not exist.");
}
Add a Policy to a User Account, Group, or Role
Add a Policy to a User Account
The following example creates a new policy, adds the new policy to an existing user account, and then
displays a list of the user account's associated policies:
// using Amazon.IdentityManagement.Resources;
// using Amazon.IdentityManagement.Model;
var iam = new IdentityManagementService();
try
{
var user = iam.GetUserByName("DemoUser");
// GenerateUserPolicyDocument() is a custom method.
string policyDoc = GenerateUserPolicyDocument();
user.CreatePolicy(policyDoc, "ListDeploymentsPolicy");
Console.WriteLine("Policies for user {0}:", user.Name);
foreach (var policyItem in user.GetPolicies())
{
Console.WriteLine(" {0}", policyItem.Name);
}
}
catch (NoSuchEntityException)
{
Console.WriteLine("User 'DemoUser' does not exist.");
}
The preceding example relies on the following example to create the new policy.
The following example doesn't use the AWS Resource APIs for .NET, as the resource APIs currently
don't support creating a policy document. However, this example is presented for completeness:
public static string GenerateUserPolicyDocument()
{
// using Amazon.Auth.AccessControlPolicy;
// Create a policy that looks like this:
/*
{
"Version" : "2012-10-17",
"Id" : "ListDeploymentsPolicy",
Version v2.0.0
101
AWS SDK for .NET Developer Guide
IAM Resource API Examples
Vista de pagina 104
1 2 ... 100 101 102 103 104 105 106 107 108 109 110 ... 154 155

Comentarios a estos manuales

Sin comentarios