private static async Task <User> CreateIamUserAsync(AWSCredentials credentials, string userName) { using (var client = new Amazon.IdentityManagement.AmazonIdentityManagementServiceClient(credentials, RegionEndpoint.EUCentral1)) { var request = new CreateUserRequest(userName); var response = await client.CreateUserAsync(request); Console.WriteLine($"User {userName} was created."); //create creds for user var createKeyRequest = new CreateAccessKeyRequest { UserName = response.User.UserName }; var accessKeyResponse = await client.CreateAccessKeyAsync(createKeyRequest); //add policy to user (demo) var attachUserPolicyRequest = new AttachUserPolicyRequest(); attachUserPolicyRequest.UserName = userName; attachUserPolicyRequest.PolicyArn = "arn:aws:iam::aws:policy/AWSElementalMediaStoreFullAccess"; await client.AttachUserPolicyAsync(attachUserPolicyRequest); return(response.User); } }
/// <summary> /// 本接口(AttachUserPolicy)可用于绑定到用户的策略。 /// </summary> /// <param name="req">参考<see cref="AttachUserPolicyRequest"/></param> /// <returns>参考<see cref="AttachUserPolicyResponse"/>实例</returns> public async Task <AttachUserPolicyResponse> AttachUserPolicy(AttachUserPolicyRequest req) { JsonResponseModel <AttachUserPolicyResponse> rsp = null; try { var strResp = await this.InternalRequest(req, "AttachUserPolicy"); rsp = JsonConvert.DeserializeObject <JsonResponseModel <AttachUserPolicyResponse> >(strResp); } catch (JsonSerializationException e) { throw new TencentCloudSDKException(e.Message); } return(rsp.Response); }
//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(); }
public Task <AttachUserPolicyResponse> AttachUserPolicyAsync(AttachUserPolicyRequest request, CancellationToken cancellationToken = new CancellationToken()) { throw new System.NotImplementedException(); }