Skip to content

Commit

Permalink
Merge pull request #66 from AlibabaCloudLandingZone/solution-fc-sts-t…
Browse files Browse the repository at this point in the history
…oken/0.0.3

solution-fc-sts-token/0.0.3
  • Loading branch information
wibud authored Jul 5, 2024
2 parents 1e97c2c + bac3c86 commit 94230f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
29 changes: 15 additions & 14 deletions solution/solution-fc-sts-token/code-example/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@
</properties>

<dependencies>
<!--2.0 vpc-sdk-->
<!--2.0 sts-sdk-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>vpc20160428</artifactId>
<version>7.8.7</version>
<artifactId>sts20150401</artifactId>
<version>1.1.4</version>
</dependency>
<!--1.0 vpc-sdk-->

<!--1.0 sts-sdk-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-sts</artifactId>
<version>3.1.2</version>
</dependency>

<!--获取所有已发布的版本列表,请参见https://github.com/aliyun/credentials-java/blob/master/ChangeLog.txt-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-vpc</artifactId>
<version>3.2.28</version>
<artifactId>credentials-java</artifactId>
<version>0.3.2</version>
</dependency>

<!--oss-sdk-->
<dependency>
<groupId>com.aliyun.oss</groupId>
Expand All @@ -57,14 +66,6 @@
<version>1.2.0</version>
</dependency>

<!--建议使用最新发布的Credentials版本。-->
<!--请查看ChangeLog.txt获取所有已发布的版本列表。-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>credentials-java</artifactId>
<version>0.3.1</version>
</dependency>

<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import com.aliyun.fc.runtime.Context;
import com.aliyun.fc.runtime.Credentials;
import com.aliyun.fc.runtime.StreamRequestHandler;
import com.aliyun.sts20150401.Client;
import com.aliyun.sts20150401.models.GetCallerIdentityResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.vpc20160428.Client;
import com.aliyun.vpc20160428.models.DescribeVpcsRequest;
import com.aliyun.vpc20160428.models.DescribeVpcsResponse;

public class App implements StreamRequestHandler {

Expand All @@ -23,11 +22,10 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
try {
Config config = new Config().setRegionId("cn-hangzhou").setCredential(createCredential(creds));

// 调用OpenAPI实现业务功能
Client vpcClient = new Client(config);
DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest().setRegionId("cn-hangzhou");
DescribeVpcsResponse describeVpcsResponse = vpcClient.describeVpcs(describeVpcsRequest);
outputStream.write(JSON.toJSONString(describeVpcsResponse).getBytes());
// 查看当前调用者身份
Client stsClient = new Client(config);
GetCallerIdentityResponse getCallerIdentityResponse = stsClient.getCallerIdentity();
outputStream.write(JSON.toJSONString(getCallerIdentityResponse).getBytes());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ async function main(context) {
accessKeyId: credentials.accessKeyId,
accessKeySecret: credentials.accessKeySecret,
securityToken: credentials.securityToken,
endpoint: 'https://vpc.cn-hangzhou.aliyuncs.com',
apiVersion: '2016-04-28'
endpoint: 'https://sts.cn-hangzhou.aliyuncs.com',
apiVersion: '2015-04-01'
});

const vpcList = await client.request('DescribeVpcs', {
const result = await client.request('GetCallerIdentity', {
pageSize: 1
}, requestOption);
return vpcList;
return result;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aliyunsdkvpc.request.v20160428 import DescribeVpcsRequest
from aliyunsdksts.request.v20150401.GetCallerIdentityRequest import GetCallerIdentityRequest
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.auth.credentials import StsTokenCredential

Expand All @@ -13,7 +13,7 @@ def handler(event, context):
client = AcsClient(region_id='cn-hangzhou', credential=credentials)

# 创建请求对象
request = DescribeVpcsRequest.DescribeVpcsRequest()
request = GetCallerIdentityRequest()

# 设置参数,例如可以设置过滤条件等,这里只展示最基本的调用
request.set_accept_format('json')
Expand Down

0 comments on commit 94230f3

Please sign in to comment.