content: package org.example.oss_sdk;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.List;
  
  import com.alibaba.fastjson2.JSON;
  import com.aliyun.fc.runtime.Context;
  import com.aliyun.fc.runtime.StreamRequestHandler;
  import com.aliyun.oss.ClientBuilderConfiguration;
  import com.aliyun.oss.OSS;
  import com.aliyun.oss.OSSClientBuilder;
  import com.aliyun.oss.common.auth.CredentialsProvider;
  import com.aliyun.oss.common.auth.DefaultCredentialProvider;
  import com.aliyun.oss.common.auth.Credentials;
  import com.aliyun.oss.common.auth.DefaultCredentials;
  import com.aliyun.oss.common.comm.SignVersion;
  import com.aliyun.oss.model.Bucket;
  
  public class App implements StreamRequestHandler {
  
      @Override
      public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
  
          // 从系统预留环境变量获取凭证信息，构造OSS的Credentials
          Credentials ossCreds = new DefaultCredentials(
              System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
              System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
              System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")
          );
  
          CredentialsProvider credentialsProvider = new DefaultCredentialProvider(ossCreds);
  
          // Bucket所在地域对应的Endpoint。以华东1（杭州）为例。
          String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
          // Endpoint对应的Region信息，例如cn-hangzhou。
          String region = "cn-hangzhou";
          // 建议使用更安全的V4签名算法，则初始化时需要加入endpoint对应的region信息，同时声明SignVersion.V4
          // OSS Java SDK 3.17.4及以上版本支持V4签名。
          ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
          configuration.setSignatureVersion(SignVersion.V4);
  
          OSS ossClient = OSSClientBuilder.create()
              .endpoint(endpoint)
              .credentialsProvider(credentialsProvider)
              .clientConfiguration(configuration)
              .region(region)
              .build();
  
          // 调用OpenAPI
          List<Bucket> buckets = ossClient.listBuckets();
          outputStream.write(JSON.toJSONString(buckets).getBytes());
      }
  }