Java SDK

Last Updated: Jul 03, 2017

Introduction

RAM SDK consists of two parts. The public part of Alibaba Cloud Java SDK depends on aliyun-java-sdk-core, and the RAM part depends on aliyun-java-sdk-ram.

For detailed use of each interface, refer to the [RAM API Documentation] (28672)

Installation

You can use Maven Repo to introduce RAM SDK or manually download RAM SDK.jar and then add it to the project.

Maven Dependencies

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-ram</artifactId>
  4. <version>2.0.7</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-core</artifactId>
  9. <version>2.2.3</version>
  10. </dependency>

Download the JAR packet

aliyun-java-sdk-core-2.2.3.jar

aliyun-java-sdk-ram-2.0.7.jar

Example

Creation of a sub-account named “alice” in RAM is used as an example:

  1. package com.aliyun.ram.sample;
  2. import com.aliyuncs.DefaultAcsClient;
  3. import com.aliyuncs.exceptions.ClientException;
  4. import com.aliyuncs.profile.DefaultProfile;
  5. import com.aliyuncs.profile.IClientProfile;
  6. // The RAM API version is 2015-05-01
  7. import com.aliyuncs.ram.model.v20150501.*;
  8. /**
  9. * Created by JasonGao on 15/11/4.
  10. */
  11. public class RamServiceSample {
  12. public static void main(String[] args) {
  13. // Construct an Aliyun Client for initiating a request
  14. // Set AccessKeyID and AccessKeySevcret when constructing the Aliyun Client
  15. // RAM is a Global Service, and its API ingress is located in the East China 1 (Hangzhou) region. Enter "cn-hangzhou" in "Region"
  16. IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",
  17. "<AccessKeyId>",
  18. "<AccessKeySecret>");
  19. DefaultAcsClient client = new DefaultAcsClient(profile);
  20. // Construct a "CreateUser" request
  21. final CreateUserRequest request = new CreateUserRequest();
  22. //Set the parameter - UserName
  23. request.setUserName("alice");
  24. // Initiate a request and obtain the response
  25. try {
  26. final CreateUserResponse response = client.getAcsResponse(request);
  27. System.out.println("UserName: " + response.getUser().getUserName());
  28. System.out.println("CreateTime: " + response.getUser().getCreateDate());
  29. } catch (ClientException e) {
  30. System.out.println("Failed.");
  31. System.out.println("Error code: " + e.getErrCode());
  32. System.out.println("Error message: " + e.getErrMsg());
  33. }
  34. }
  35. }

Release Notes

Version: 2.0.7

Released on November 7, 2015

  • The first version of RAM Java SDK contains all APIs of RAM
Thank you! We've received your feedback.