Often when working with AWS and Spring using the aws-java-sdk, we need to create clients for different services. This autoconfigure module when included in the pom, will create the required clients for the AWS services and put it in bean factory ready for injection.
There is already a project spring-cloud-aws from Spring under the Spring Cloud umbrella. However, for some people that can be an overwhelming amount of abstraction and would like to work with the native SDK. This can be useful to those people.
AWS credential management works the same way as the native SDK.
Region selection takes place with the following precedence:
- Region configured in application.properties / yml file
- If running on AWS (EC2 / Fargate) then, the region of the EC2 instance / ECS Cluster
- Default AWS Region
As of now, Supports the following AWS Services (i.e. create AWS Clients bean for the service)
- Simple Storage Service - S3 (
AmazonS3
) - Simple Queue Service - SQS (
AmazonSQS
,AmazonSQSAsync
) - Simple Notification Service - SNS (
AmazonSNS
,AmazonSNSAsync
) - Simple Email Service - SES (
AmazonSimpleEmailService
,AmazonSimpleEmailServiceAsync
)
This project is managed by maven, run
mvn clean install
Just add the starter as a maven dependency:
<dependency>
<groupId>org.ares</groupId>
<artifactId>aws-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
Then autowire the required bean and use it
public class S3ObjectDownloader {
@Autowired
private AmazonS3 amazonS3;
public void downloadObj(String bucket, String s3Key) {
S3Obejct object = amazonS3.getObject(bucket, s3Key);
// use the object
}
}