본문 바로가기

서버

aws ec2) spring에서 s3업로드시 "profile file cannot be null"오류현상

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>