From 55eae1bca42e13104f4fb03327157c620ecbd902 Mon Sep 17 00:00:00 2001 From: Dongyun Kim Date: Wed, 8 Jan 2025 18:34:33 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#1=20S3=20=EB=B2=84=EC=BC=93=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weditapp/global/config/AwsConfig.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/wedit/weditapp/global/config/AwsConfig.java diff --git a/src/main/java/com/wedit/weditapp/global/config/AwsConfig.java b/src/main/java/com/wedit/weditapp/global/config/AwsConfig.java new file mode 100644 index 0000000..a126e0e --- /dev/null +++ b/src/main/java/com/wedit/weditapp/global/config/AwsConfig.java @@ -0,0 +1,34 @@ +package com.wedit.weditapp.global.config; + +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; + +@Configuration +public class AwsConfig { + @Value("${cloud.aws.credentials.access-key}") + private String accessKey; + + // S3를 등록한 사람이 전달받은 접속하기 위한 secret key 값 + @Value("${cloud.aws.credentials.secret-key}") + private String secretKey; + + // S3를 등록한 사람이 S3를 사용할 지역 + @Value("${cloud.aws.region.static}") + private String region; + + // 전달받은 Accesskey 와 SecretKey 로 아마존 서비스 실행 준비 + @Bean + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); + return (AmazonS3Client)AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) + .build(); + } +}