728x90
로컬에서 업로드시에는 잘 되었는데
ec2에 올리니까 오류가 나타났다.
해당 현상은 stackoverflow에서는
AmazonS3Client 객체 생성시에
profile에 대한 내용의 파라미터가 안들어가서
객체생성에 실패했다는 내용이 많았다.
spring cloud aws starter 패키지를 제일 최신버전으로 받았더니
잘 되더라..
S3Config.java
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
@Configuration
public class S3Config {
@Value("${cloud.aws.credentials.access-key}")
private String iamAccessKey;
@Value("${cloud.aws.credentials.secret-key}")
private String iamSecretKey;
@Value("${cloud.aws.region.static}")
private String region;
@Bean
public AmazonS3Client amazonS3Client() throws JsonMappingException, JsonProcessingException{
System.out.println(">>>>>>###### " + region);
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(iamAccessKey, iamSecretKey);
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withRegion(region).enablePathStyleAccess()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
}
pom.xml
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
'서버' 카테고리의 다른 글
vue)vite프로젝트 static 파일 (이미지) 접근 안될 때 (0) | 2024.03.11 |
---|---|
nas) express.js git clone 하여 서버 실행하기(백그라운드로 서버 켜두기) (0) | 2024.03.11 |
aws ec2) 로드밸런서 말고 nginx로 ssl 적용시키기 (ubuntu) (0) | 2024.03.02 |
aws ec2) 도메인 적용하기 (ssl 적용 전에 테스트, 가비아 이용) (0) | 2024.03.02 |
aws ec2) ubuntu 환경에서 nginx, tomcat(8.5), java(1.8) 셋팅 (0) | 2024.03.01 |