Skip to content

Commit e5c8216

Browse files
authored
Merge pull request thombergs#302 from hardikSinghBehl/codebase/spring-cloud-aws-s3
codebase/spring-cloud-aws-s3
2 parents 71e243e + cdbc755 commit e5c8216

File tree

22 files changed

+1225
-0
lines changed

22 files changed

+1225
-0
lines changed

aws/spring-cloud-aws-s3/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### VS Code ###
23+
.vscode/
24+
25+
### Mac OS ###
26+
.DS_Store
61.1 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar

aws/spring-cloud-aws-s3/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM maven:3.9-amazoncorretto-21 as backend
2+
WORKDIR /backend
3+
COPY pom.xml .
4+
COPY lombok.config .
5+
RUN mvn dependency:go-offline -B
6+
COPY src ./src
7+
RUN mvn clean install -DskipITs
8+
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
9+
10+
FROM openjdk:21
11+
ARG DEPENDENCY=/backend/target/dependency
12+
COPY --from=backend ${DEPENDENCY}/BOOT-INF/lib /app/lib
13+
COPY --from=backend ${DEPENDENCY}/META-INF /app/META-INF
14+
COPY --from=backend ${DEPENDENCY}/BOOT-INF/classes /app
15+
ENTRYPOINT ["java", "-cp", "app:app/lib/*", "io.reflectoring.Application"]

aws/spring-cloud-aws-s3/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Interacting with Amazon S3 Bucket using Spring Cloud AWS
2+
3+
Codebase demonstrating connection and interaction with provisioned Amazon S3 bucket using [Spring Cloud AWS](https://spring.io/projects/spring-cloud-aws).
4+
5+
Contains integration tests to validate interaction between the application and Amazon S3 using [LocalStack](https://github.com/localstack/localstack) and [Testcontainers](https://github.com/testcontainers/testcontainers-java). Test cases can be executed with the command `./mvnw integration-test verify`.
6+
7+
To run the application locally without provisioning actual AWS Resources, execute the below commands:
8+
9+
```bash
10+
chmod +x localstack/init-s3-bucket.sh
11+
```
12+
13+
```bash
14+
sudo docker-compose build
15+
```
16+
17+
```bash
18+
sudo docker-compose up -d
19+
```
20+
21+
## Blog posts
22+
23+
Blog posts about this topic:
24+
25+
* [Using Amazon S3 with Spring Cloud AWS](https://reflectoring.io/spring-cloud-aws-s3/)
26+
* [Using AWS S3 Presigned URLs in Spring Boot](https://reflectoring.io/aws-s3-presigned-url-spring-boot/)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3.7'
2+
3+
services:
4+
localstack:
5+
container_name: localstack
6+
image: localstack/localstack:3.3
7+
ports:
8+
- 4566:4566
9+
environment:
10+
- SERVICES=s3
11+
volumes:
12+
- ./localstack/init-s3-bucket.sh:/etc/localstack/init/ready.d/init-s3-bucket.sh
13+
networks:
14+
- reflectoring
15+
16+
backend:
17+
container_name: backend-application
18+
build:
19+
context: ./
20+
dockerfile: Dockerfile
21+
ports:
22+
- 8080:8080
23+
depends_on:
24+
- localstack
25+
environment:
26+
spring.cloud.aws.s3.endpoint: 'http://localstack:4566'
27+
spring.cloud.aws.s3.path-style-access-enabled: true
28+
spring.cloud.aws.credentials.access-key: test
29+
spring.cloud.aws.credentials.secret-key: test
30+
spring.cloud.aws.s3.region: 'us-east-1'
31+
io.reflectoring.aws.s3.bucket-name: 'reflectoring-bucket'
32+
io.reflectoring.aws.s3.presigned-url.validity: 120
33+
networks:
34+
- reflectoring
35+
36+
networks:
37+
reflectoring:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
bucket_name="reflectoring-bucket"
3+
4+
awslocal s3api create-bucket --bucket $bucket_name
5+
6+
echo "S3 bucket '$bucket_name' created successfully"
7+
echo "Executed init-s3-bucket.sh"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lombok.nonNull.exceptionType=IllegalArgumentException

0 commit comments

Comments
 (0)