Skip to content

Commit

Permalink
✨ feat(api): Add AWS S3 Config, S3 Service (#221)
Browse files Browse the repository at this point in the history
* ✨ feat(api): Add AWS S3 Config, S3 Service

* ✨ feat(api): remove hard coding strings
  • Loading branch information
yunyoung1819 authored and seonghun-dev committed Jul 18, 2023
1 parent 1050ab0 commit 1381b3a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/streetdrop-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.3.1'
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.depromeet.external.aws.s3;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AwsS3Config {

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.s3.region.static}")
private String region;


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

@Bean
public AmazonS3 amazonS3(BasicAWSCredentials basicAWSCredentials) {
return AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.depromeet.external.aws.s3;

import com.amazonaws.services.s3.AmazonS3;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AwsS3Service {
private final AmazonS3 amazonS3;

@Value("${cloud.aws.s3.bucket}")
private String bucket;

public String getS3(String bucket, String fileName) {
return amazonS3.getUrl(bucket, fileName).toString();
}

public String getS3FilePaths() {
return bucket;
}
}

0 comments on commit 1381b3a

Please sign in to comment.