区域链接技术java,AWS Java SDK-无法通过区域提供者链找到区域

I have gone through the question titled "Setting the AWS region programmatically 1" but it doesn't provide all the answers I need.

Q1: I'm getting a SDKClientException-Unable to find a region via the region provider chain. What am I doing wrong? or is there a typo that I missed.

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());

}

}

}

Q2: What code changes needs to be done if I want to build a Lambda Function out of it? I'm aware how to create a lambda function and roles that it needs. Just need to know if the code that I have written needs to changed. How should I implement the LambdaFuctionHandler class as below:

import com.amazonaws.services.lambda.runtime.Context;

import com.amazonaws.services.lambda.runtime.RequestHandler;

public class LambdaFunctionHandler implements RequestHandler {

@Override

public String handleRequest(String input, Context context) {

context.getLogger().log("Input: " + input);

return null;

}

}

解决方案

Regarding Q1, try to build your client using the following syntax:

AmazonS3 amazonS3 = AmazonS3Client.builder()

.withRegion("us-east-1")

.withCredentials(new AWSStaticCredentialsProvider(creds))

.build();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值