User guide
group.CreatePolicy(policyDoc, "ListDeploymentConfigsPolicy");
Console.WriteLine("Policies for group {0}:", group.Name);
foreach (var policyItem in group.GetPolicies())
{
Console.WriteLine(" {0}", policyItem.Name);
}
}
catch (NoSuchEntityException)
{
Console.WriteLine("Group 'DemoGroup' 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 GenerateGroupPolicyDocument()
{
// using Amazon.Auth.AccessControlPolicy;
// Create a policy that looks like this:
/*
{
"Version" : "2012-10-17",
"Id": "ListDeploymentConfigsPolicy",
"Statement" : [
{
"Sid" : "ListDeploymentConfigsStatement",
"Effect" : "Allow",
"Action" : "codedeploy:ListDeploymentConfigs",
"Resource" : "*"
}
]
}
*/
var action = new ActionIdentifier("codedeploy:ListDeploymentConfigs");
var actions = new List<ActionIdentifier>();
actions.Add(action);
var resource = new Resource("*");
var resources = new List<Resource>();
resources.Add(resource);
var statement = new Statement(Statement.StatementEffect.Allow)
{
Actions = actions,
Id = "ListDeploymentConfigsStatement",
Resources = resources
};
var statements = new List<Statement>();
Version v2.0.0
103
AWS SDK for .NET Developer Guide
IAM Resource API Examples