in solution/solution-fc-sts-token/code-example/java/src/main/java/org/example/sls_sdk/App.java [22:43]
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
// 从上下文获取凭证信息
com.aliyun.fc.runtime.Credentials creds = context.getExecutionCredentials();
// 转化为SLS的Credentials
Credentials slsCreds = new DefaultCredentials(creds.getAccessKeyId(), creds.getAccessKeySecret(), creds.getSecurityToken());
CredentialsProvider credentialsProvider = new StaticCredentialsProvider(slsCreds);
// SLS endpoint,以杭州为例
String endpoint = "https://cn-hangzhou.log.aliyuncs.com";
Client slsClient = new Client(endpoint, credentialsProvider);
// 调用OpenAPI
try {
List<Project> projects = slsClient.ListProject().getProjects();
outputStream.write(JSON.toJSONString(projects).getBytes());
} catch (LogException e) {
throw new RuntimeException(e);
}
}