无法通过Beanstalk将图像上传到S3

时间:2017-05-17 09:47:08

标签: spring-boot amazon-s3 amazon-ec2 elastic-beanstalk

我无法通过使用以下方法部署在Amazon Elastic Beanstalk上的Spring Boot应用程序将图像上传到S3:

    @Autowired
    private AmazonS3Client amazonS3Client;

    amazonS3Client.setEndpoint(S3_REGION_ENDPOINT);
    amazonS3Client.putObject(new PutObjectRequest(S3_BUCKET_NAME, key, fileToUpload));

日志显示以下错误:

Caused by: java.io.IOException: Permission denied
    at java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:1012)
    at com.g2m.persistence.image.service.FileArchiveService.convertFromMultiPart(FileArchiveService.java:91)
    at com.g2m.persistence.image.service.FileArchiveService.saveFileToS3(FileArchiveService.java:44)

但是当尝试使用本地端点(在本地运行Spring Boot)上传图像时,我设法成功将图像上传到S3并检索它。

知道如何解决这个问题?它与S3权限有关或什么都没有?

1 个答案:

答案 0 :(得分:0)

在我看来,您没有正确实例化S3客户端。您可以检查在实例化时是否提供了正确的凭据吗?

这样的东西
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
amazonS3Client = new AmazonS3Client(credentials);
相关问题