How to create a new user in AWS

时光怂恿深爱的人放手 提交于 2019-12-06 02:09:15

问题


I'm trying to figure out how to create a new user with AWS APIs for Java, but i can't figure out what i need to do.

So far i managed to write this code that gives me a CreateUserRequest, a CreateAccessKeyRequest and a BasicAWSCredentials with all the fields filled.

I just can't figure out what to do next. Do I have to use CreateUserResult? How?

    CreateUserRequest user = new CreateUserRequest("userName");

    CreateAccessKeyRequest key = new CreateAccessKeyRequest();

    BasicAWSCredentials cred = new BasicAWSCredentials("access", "secret");

    key.withUserName(user.getUserName());
    key.setRequestCredentials(cred);

    user.setRequestCredentials(key.getRequestCredentials());
    user.setPath("/");

EDIT: I'm still working on this today.

I think I need to use the createUser(CreateUserRequest) method of AmazonIdentityManagementClient class. (which returns a CreateUserResult, I was not supposed to instantiate this class manually)

Problem is, I don't know how to properly initialize this class with the right AWSCredentials (I'm using the account's AccessKey and SecretAccessKey).


回答1:


CreateUserRequest user = new CreateUserRequest("userName");

CreateAccessKeyRequest key = new CreateAccessKeyRequest();

BasicAWSCredentials cred = new BasicAWSCredentials("access", "secret");

key.withUserName(user.getUserName());
key.setRequestCredentials(cred);

user.setRequestCredentials(key.getRequestCredentials());
user.setPath("/");
AmazonIdentityManagementClient client =  new AmazonIdentityManagementClient(cred);
CreateUserResult result = client.createUser(user);



回答2:


Maybe this link can help you :

http://docs.amazonwebservices.com/IAM/latest/APIReference/API_CreateUser.html

I've not played with Amazon S3 service, but with another service like it and I had to create the Request manually and sign the request with correct data.



来源:https://stackoverflow.com/questions/12711975/how-to-create-a-new-user-in-aws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!