-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(api): Add AWS S3 Config, S3 Service (#221)
* ✨ feat(api): Add AWS S3 Config, S3 Service * ✨ feat(api): remove hard coding strings
- Loading branch information
1 parent
1050ab0
commit 1381b3a
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
backend/streetdrop-api/src/main/java/com/depromeet/external/aws/s3/AwsS3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/streetdrop-api/src/main/java/com/depromeet/external/aws/s3/AwsS3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |