AWS Java SDK-无法通过区域提供者链找到区域

我经历了题为“以编程方式将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;

}

}

回答:

关于Q1,请尝试使用以下语法构建客户端:

AmazonS3 amazonS3 = AmazonS3Client.builder()

.withRegion("us-east-1")

.withCredentials(new AWSStaticCredentialsProvider(creds))

.build();

以上是 AWS Java SDK-无法通过区域提供者链找到区域 的全部内容, 来源链接: utcz.com/qa/402681.html

回到顶部