Mesmo seguindo passo a passo recebo mensagem de erro ao tentar salvar um novo livro que envia a imagem para um bucket. Configurei exatamente como nos vídeos e já conferi as senhas(baixei o .csv), porém não consigo cadastrar.
Alguma ideia ? Obs.: notei que em minha Secret key existe o caractere : '/' isso pode ser a origem do problema ?
com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: E0C7BF48A45BA265), S3 Extended Request ID: QutDQ3+DC5Kk57OhIRLDoVCy440yjUbKCdj54eFicUQXrHoSVGPr33vaBB12UX+gqN4YrTsVhwg=
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1588)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1258)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4169)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4116)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1700)
at br.com.casadocodigo.loja.infra.FileSaver.write(FileSaver.java:21)
@Component
public class FileSaver {
@Autowired
private AmazonS3 amazonS3;
private static final String BUCKET = "ocultei-nome-do-meu-bucket";
public String write(MultipartFile file) {
try {
amazonS3.putObject(new PutObjectRequest(BUCKET, file.getOriginalFilename(), file.getInputStream(), null)
.withCannedAcl(CannedAccessControlList.PublicRead));
return "http://s3.amazonaws.com/" + BUCKET + "/" + file.getOriginalFilename();
} catch (IllegalStateException | IOException e) {
throw new RuntimeException(e);
}
}
}
@Configuration
public class AmazonConfiguration {
private static final String ACCES_KEY="AAAAAAAAAAA";
private static final String SECRET_KEY="AAAAAAAA/AAAAAAAAA";
private static final String REGION="us-east-1";
@Bean
public BasicAWSCredentials basicAWSCredentials (){
return new BasicAWSCredentials(ACCES_KEY, SECRET_KEY);
}
@Bean
public AmazonS3 amazonS3() {
return AmazonS3ClientBuilder.standard().withRegion(REGION)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials())).build();
}
}