Amazon AWS SDK Guide de l'utilisateur Page 108

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 155
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 107
statements.Add(statement);
var policy = new Policy
{
Id = "ListDeploymentConfigsPolicy",
Version = "2012-10-17",
Statements = statements
};
return policy.ToJson();
}
Add a Policy to a Role
The following example creates a new policy and then adds the new policy to an existing role.
The following example doesn't use the AWS Resource APIs for .NET, as the resource APIs currently
don't support adding a policy to a role. However, this example is presented for completeness:
// using Amazon.IdentityManagement;
// using Amazon.IdentityManagement.Model;
var client = new AmazonIdentityManagementServiceClient();
// GenerateRolePolicyDocument() is a custom method.
string policyDoc = GenerateRolePolicyDocument();
var request = new PutRolePolicyRequest
{
RoleName = "DemoEC2",
PolicyName = "DemoEC2Permissions",
PolicyDocument = policyDoc
};
try
{
client.PutRolePolicy(request);
}
catch (NoSuchEntityException)
{
Console.WriteLine
("Role 'DemoEC2' or policy 'DemoEC2Permissions' 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 GenerateRolePolicyDocument()
{
// using Amazon.Auth.AccessControlPolicy;
// Create a policy that looks like this:
/*
{
Version v2.0.0
104
AWS SDK for .NET Developer Guide
IAM Resource API Examples
Vue de la page 107
1 2 ... 103 104 105 106 107 108 109 110 111 112 113 ... 154 155

Commentaires sur ces manuels

Pas de commentaire