public void IdentityManagementServiceAttachUserPolicy() { #region 1372ebd8-9475-4b1a-a479-23b6fd4b8b3e var client = new AmazonIdentityManagementServiceClient(); var response = client.AttachUserPolicy(new AttachUserPolicyRequest { PolicyArn = "arn:aws:iam::aws:policy/AdministratorAccess", UserName = "******" }); #endregion }
//Button3 - Policy private void button3_Click(object sender, EventArgs e) { txtOutput.Text += "Creating Policy" + "\r\n"; var client = new AmazonIdentityManagementServiceClient(); string policyDoc = GenerateUserPolicyDocument(bucketName); var request = new CreatePolicyRequest { PolicyName = bucketName + "Policy", PolicyDocument = policyDoc }; try { var createPolicyResponse = client.CreatePolicy(request); txtOutput.Text += "Policy named " + createPolicyResponse.Policy.PolicyName + " Created." + "\r\n"; policyarn = createPolicyResponse.Policy.Arn; } catch (EntityAlreadyExistsException) { txtOutput.Text += "Policy " + bucketName + " already exits." + "\r\n"; } txtOutput.Text += "Attaching policy to User" + "\r\n"; var attachrequest = new AttachUserPolicyRequest { UserName = bucketName, PolicyArn = policyarn }; try { var createPolicyResponse = client.AttachUserPolicy(attachrequest); txtOutput.Text += "Policy applied" + "\r\n"; } catch (Exception) { txtOutput.Text += "Attach Failed" + "\r\n"; } txtOutput.ScrollToCaret(); }