From 19afc1f8a2614873bc90b665000259455259691b Mon Sep 17 00:00:00 2001 From: hyeesw Date: Sat, 24 Aug 2024 14:50:28 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#72=20s3=20=EC=B4=88=EA=B8=B0=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ .../com/book/backend/global/s3/S3Config.java | 30 +++++++++++++++++++ src/main/resources/application.yml | 12 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/java/com/book/backend/global/s3/S3Config.java diff --git a/build.gradle b/build.gradle index c0825080..56745579 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,9 @@ dependencies { // jwt implementation 'io.jsonwebtoken:jjwt:0.9.1' + //s3 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + developmentOnly 'org.springframework.boot:spring-boot-devtools' compileOnly 'org.projectlombok:lombok' diff --git a/src/main/java/com/book/backend/global/s3/S3Config.java b/src/main/java/com/book/backend/global/s3/S3Config.java new file mode 100644 index 00000000..ee15360b --- /dev/null +++ b/src/main/java/com/book/backend/global/s3/S3Config.java @@ -0,0 +1,30 @@ +package com.book.backend.global.s3; + +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.beans.factory.annotation.Value; +import com.amazonaws.services.s3.AmazonS3; + +@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 AmazonS3 s3Client() { + AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); + + return AmazonS3ClientBuilder.standard() + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .withRegion(region) + .build(); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5c424ea8..570c5d67 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -53,3 +53,15 @@ jwt: secretKey: ${JWT_SECRET} accessTokenExpireTime: ${ACCESS_TOKEN_EXPIRE_TIME} refreshTokenExpireTime: ${REFRESH_TOKEN_EXPIRE_TIME} + +cloud: + aws: + s3: + bucket: ${AWS_S3_BUCKET_NAME} + credentials: + access-key: ${AWS_S3_BUCKET_ACCESS_KEY} + secret-key: ${AWS_S3_BUCKET_SECRET_KEY} + region: + static: ap-northeast-2 # 버킷 생성 지역 + stack: + auto: false #??