danuri
오늘의 기록
danuri
전체 방문자
오늘
어제
  • 오늘의 기록 (307)
    • java (150)
      • java (33)
      • spring (63)
      • jpa (36)
      • querydsl (7)
      • intelliJ (9)
    • kotlin (8)
    • python (24)
      • python (10)
      • data analysis (13)
      • crawling (1)
    • ddd (2)
    • chatgpt (2)
    • algorithm (33)
      • theory (9)
      • problems (23)
    • http (8)
    • git (8)
    • database (5)
    • aws (12)
    • devops (10)
      • docker (6)
      • cicd (4)
    • book (44)
      • clean code (9)
      • 도메인 주도 개발 시작하기 (10)
      • 자바 최적화 (11)
      • 마이크로서비스 패턴 (0)
      • 스프링으로 시작하는 리액티브 프로그래밍 (14)
    • tistory (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

인기 글

태그

  • mockito
  • Spring
  • POSTGIS
  • Java
  • 도메인 주도 설계
  • SWAGGER
  • 등가속도 운동
  • S3
  • docker
  • Jackson
  • Thymeleaf
  • Saving Plans
  • PostgreSQL
  • ChatGPT
  • Kotlin
  • Security
  • 자바 최적화
  • JPA
  • gitlab
  • CICD
  • DDD
  • Database
  • nuribank
  • 마이크로서비스패턴
  • 트랜잭션
  • Bitmask
  • AWS
  • connection
  • RDS
  • reactive

최근 댓글

최근 글

hELLO · Designed By 정상우.
danuri

오늘의 기록

java/spring

[Spring] AWS S3 접근

2022. 7. 25. 17:25

라이브러리 추가

implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

 

인증 키 추가

<application.yml>
본인 IAM 인증 키를 추가하면 된다.

cloud:
  aws:
    credentials:
      instance-profile: false
      access-key: [access-key]
      secret-key: [secret-key]
    region:
      auto: false
      static: ap-northeast-2
    stack:
      auto: false

 

S3Config

@Configuration
public class S3Config {

    @Value("${cloud.aws.credentials.access-key}")
    public String accessKey;
    @Value("${cloud.aws.credentials.secret-key}")
    public String secretKey;
    @Value("${cloud.aws.region.static}")
    public String region;

    @Bean
    @Primary
    public BasicAWSCredentials awsCredentialsProvider(){
        BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);
        return basicAWSCredentials;
    }

    @Bean
    public AmazonS3 amazonS3() {
        AmazonS3 s3Builder = AmazonS3ClientBuilder.standard()
                .withRegion(region)
                .withCredentials(new AWSStaticCredentialsProvider(awsCredentialsProvider()))
                .build();
        return s3Builder;
    }
}

 

 


 

이제 amazonS3.getObject() 등 S3에 접근할 수 있다.

 

 

 

 

저작자표시 비영리 동일조건 (새창열림)

'java > spring' 카테고리의 다른 글

[Spring] Failed to validate connection  (0) 2022.08.03
[Spring] AWS S3 객체 전체 조회 or 해당 level만 조회  (0) 2022.08.01
[Spring] S3 Pre-Signed URL 생성  (0) 2022.07.25
[Spring] @Value, static 변수에 사용하기  (0) 2022.07.22
[Spring] Spring Security + Swagger 3.0 적용  (0) 2022.07.22
    'java/spring' 카테고리의 다른 글
    • [Spring] Failed to validate connection
    • [Spring] AWS S3 객체 전체 조회 or 해당 level만 조회
    • [Spring] S3 Pre-Signed URL 생성
    • [Spring] @Value, static 변수에 사용하기
    danuri
    danuri
    IT 관련 정보(컴퓨터 지식, 개발)를 꾸준히 기록하는 블로그입니다.

    티스토리툴바