AWS S3 | JeongKeepsCalm

AWS S3

Bucket & IAM

  1. AWS S3 버킷 생성
    • ACL 활성화
    • 모든 파일 엑세스 차단 체크 해제
  2. 버킷 접근 권한 설정
    • 생성된 버킷 > 권한 > ACL(엑세스 제어 목록) 편집: 모든 사람(퍼블릭 엑세스) 읽기 권한 체크
  3. IAM S3 접근 계정 생성
    • 사용자 그룹 생성: AmazonS3FullAccess 추가
    • 사용자 생성: 생성 시 새로 만든 S3 그룹 지정
    • 생성된 유저 > 보안 자격 증명 > 엑세스 키 만들기
      • access-key, secret-access-key 기억
  4. 스프링 부트 변수 설정
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
     cloud:
       aws:
         s3:
           # s3 버킷명
           bucket: first-bucket
         stack:
           auto: false
         region:
           # aws 버킷 지역
           static: ap-northeast-2
         credentials:
           # IAM 사용자 정보
           access-key: dsajfdafdafdafsdfdafdsaf
           secret-key: dfdsfdsfsdfsaaerwareasrearewaaees
    
  5. 스프링 부트 AWS S3 연결 및 Config 클래스 작성
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
     @Configuration
     public class S3Config {
    
         @Value("${cloud.aws.credentials.access-key}")
         private String accessKey;
    
         @Value("${cloud.aws.credentials.secret-key}")
         private String secretKey;
    
         @Value("${cloud.aws.region.static}")
         private String region;
    
         @Bean
         public AmazonS3Client amazonS3Client() {
             BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
             return (AmazonS3Client) AmazonS3ClientBuilder.standard()
                     .withRegion(region)
                     .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
                     .build();
         }
    
     }