Skip to content

Commit

Permalink
Merge pull request #68 from AlibabaCloudLandingZone/solution-ecs-sts-…
Browse files Browse the repository at this point in the history
…token/0.0.4

solution-ecs-sts-token/0.0.4
  • Loading branch information
wibud authored Jul 5, 2024
2 parents abfcbc9 + 8e9e39e commit b9ff85d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
阿里云V1.0 SDK是较早使用版本,稳定性良好,不少老用户习惯于原版SDK的开发,本示例为用户提供一个简练的使用指南。对于新用户则建议直接使用新版SDK,老用户也建议尽早迁移到新版SDK。

本示例完成SDK客户端的初始化后,调用API:GetCallerIdentity获取当前调用者身份信息。

如果您需要从长期固定AccessKey的使用方式进行迁移,只需修改少量代码即可完成,如下图所示,左侧一栏是使用固定AccessKey初始化阿里云SDK,右侧一栏是使用Credentials工具初始化阿里云SDK。

![](./code-diff.png)

#### 环境要求
该示例代码需要在ECS环境中执行,执行前,请确保运行环境中已配置好Java和Maven。
1. Java Development Kit (JDK):确保已安装Java 8或更高版本。
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static void main(String[] args) throws Exception {
Client credentialsClient = new Client();

// 调用API,以GetCallerIdentity获取当前调用者身份信息为例
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
config.setCredential(credentialsClient);
config.setEndpoint("sts.cn-hangzhou.aliyuncs.com");
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setCredential(credentialsClient)
.setEndpoint("sts.cn-hangzhou.aliyuncs.com");
com.aliyun.sts20150401.Client stsClient = new com.aliyun.sts20150401.Client(config);

GetCallerIdentityResponse getCallerIdentityResponse = stsClient.getCallerIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static void main(String[] args) throws Exception {
Client credentialsClient = new Client(credentialConfig);

// 调用API,以GetCallerIdentity获取当前调用者身份信息为例
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
config.setCredential(credentialsClient);
config.setEndpoint("sts.cn-hangzhou.aliyuncs.com");
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setCredential(credentialsClient)
.setEndpoint("sts.cn-hangzhou.aliyuncs.com");
com.aliyun.sts20150401.Client stsClient = new com.aliyun.sts20150401.Client(config);

GetCallerIdentityResponse getCallerIdentityResponse = stsClient.getCallerIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
使用V2.0版本的阿里云SDK时,集成阿里云的Credentials工具,使您能够轻松地获取和管理访问凭证。基于实例RAM角色获取临时凭证时,Credentials工具会自动获取ECS实例绑定的RAM角色,并调用ECS的元数据服务(Meta Data Server)获取临时访问凭证,该凭证会周期性更新。

本示例完成SDK客户端的初始化后,调用API:GetCallerIdentity获取当前调用者身份信息。

如果您需要从长期固定AccessKey的使用方式进行迁移,只需修改少量代码即可完成,如下图所示,左侧一栏是使用固定AccessKey初始化阿里云SDK,右侧一栏是使用Credentials工具初始化阿里云SDK。

![](./code-diff.png)

#### 环境要求
该示例代码需要在ECS环境中执行,执行前,请确保运行环境中已配置好Java和Maven。
1. Java Development Kit (JDK):确保已安装Java 8或更高版本。
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b9ff85d

Please sign in to comment.