AWS Java 开发工具包 - 无法通过区域提供商链查找区域
2022-08-31 13:19:23
我已经回答了标题为“以编程方式设置 AWS 区域 1”的问题,但它没有提供我需要的所有答案。
Q1: 我得到了一个 .我做错了什么?还是我错过了一个错别字。SDKClientException-Unable to find a region via the region provider chain
public class CreateS3Bucket {
public static void main(String[] args) throws IOException {
BasicAWSCredentials creds = new BasicAWSCredentials("aws-access-key", "aws-secret-key");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).build();
Region region = Region.getRegion(Regions.US_EAST_1);
s3Client.setRegion(region);
try {
String bucketName = "testBucket" + UUID.randomUUID();
s3Client.createBucket(bucketName);
System.out.println("Bucket Created Successfully.");
} catch(AmazonServiceException awse) {
System.out.println("This means that your request made it AWS S3 but got rejected");
System.out.println("Error Message:" +awse.getMessage());
System.out.println("Error Message:" +awse.getErrorCode());
System.out.println("Error Message:" +awse.getErrorType());
System.out.println("Error Message:" +awse.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("The Amazon Client encountered an Error with network Connectivity");
System.out.println("Error Message:" + ace.getMessage());
}
}
}
问题 2:如果我想从中构建 Lambda 函数,需要更改哪些代码?我知道如何创建一个lambda函数和它需要的角色。只需要知道我编写的代码是否需要更改。我应该如何实现 LambdaFuctionHandler 类,如下所示:
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunctionHandler implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {
context.getLogger().log("Input: " + input);
return null;
}
}