DevOps

[Spring boot] AWS S3 연동 관련 에러 해결 모음

CloudFormation 관련 에러

 

에러 내용 요약: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.aws.core.env.ResourceIdResolver.BEAN_NAME' ~ cloudformation ~

 

spring-cloud-starter-aws 의존성을 사용해서 연동하게 되면 프로젝트 실행 시 기본으로 CloudFormation 구성을 시작한다. 따라서 설정한 CloudFormation이 없으면 프로젝트 실행이 되지 않아서 발생하는 에러이다.

 

해결책

// .properties
cloud.aws.stack.auto=false

// .yml
cloud:
  aws:
    stack:
      auto: false

 

 

AmazonS3 빈을 생성하지 못한다 블라블라

에러 내용 요약: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amazonS3': Invocation of init method failed; nested exception is java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance

 

 

내 경우 local에서는 FakeS3 객체가 돌아가도록 하고, dev, prod 환경에서는 S3 객체가 돌아가도록 구성했다. 그래서 로컬에서는 S3Configuration이 동작하지 않기 때문에, aws region 관련 정보가 필요없다고 생각했다. 하지만 어쨌든 local에서도 구동시키기 위해서는 region 정보를 명시해줘야해서 발생하는 에러였다.

 

해결책

// .properties
cloud.aws.region.static= ap-northeast-2

// .yml
cloud:
  aws:
    region:
      static: ap-northeast-2