Created
January 15, 2021 15:29
-
-
Save mmafrar/10a22cc93629949d41c9bf9cbde1ddaa to your computer and use it in GitHub Desktop.
Integrating your Spring Boot project with Amazon S3
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
package com.example.demo; | |
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 FileConfiguration { | |
@Value("${access.key.id}") | |
private String accessKeyId; | |
@Value("${access.key.secret}") | |
private String accessKeySecret; | |
@Value("${s3.region.name}") | |
private String s3RegionName; | |
@Bean | |
public AmazonS3 getAmazonS3Client() { | |
final BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKeyId, accessKeySecret); | |
// Get Amazon S3 client and return the S3 client object | |
return AmazonS3ClientBuilder | |
.standard() | |
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials)) | |
.withRegion(s3RegionName) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment