awss3在java应用程序中使用localstack return500

eulz3vhy  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(200)

我正在用springboot开发一个java应用程序。我正在使用“awsjavasdk”,并用localstack模拟aws。
但是当我尝试用下面的代码将它插入到bucket s3(以前在localstack上创建)中时,它返回:“(服务:amazons3;状态代码:500;错误代码:500;请求id:33c21ac340bc212f)
由于这是一个错误,我想不出原因。拜托,我怎么解决?

  1. public void storeFile(File file) {
  2. try {
  3. AmazonS3 s3Client = createS3Client();
  4. String fileName = file.getName();
  5. s3Client.putObject(bucketName, fileName, file);
  6. } catch (AmazonServiceException e) {
  7. throw new RuntimeException();
  8. } catch (SdkClientException e) {
  9. throw new RuntimeException();
  10. }
  11. }
  12. private AmazonS3 createS3Client() {
  13. AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
  14. if (s3Endpoint != null) {
  15. AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration(s3Endpoint, region);
  16. return AmazonS3ClientBuilder.standard()
  17. .withEndpointConfiguration(endpoint)
  18. .withCredentials(new AWSStaticCredentialsProvider(credentials))
  19. .build();
  20. }
  21. Regions clientRegion = Regions.fromName(region);
  22. return AmazonS3ClientBuilder.standard()
  23. .withRegion(clientRegion)
  24. .withCredentials(new AWSStaticCredentialsProvider(credentials))
  25. .build();
  26. }

以下变量由环境变量加载:region、s3endpoint、bucketname、awsaccesskey和awssecretkey。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题