Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new user in AWS

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).

like image 860
Eugenio Laghi Avatar asked Oct 03 '12 15:10

Eugenio Laghi


1 Answers

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);
like image 75
Oskar Kjellin Avatar answered Oct 06 '22 02:10

Oskar Kjellin