Skip to content

Commit

Permalink
Merge branch 'master' into ranjani-spring-security-jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjanih committed May 28, 2024
2 parents e5a8259 + e5c8216 commit 4f4387b
Show file tree
Hide file tree
Showing 113 changed files with 7,382 additions and 0 deletions.
26 changes: 26 additions & 0 deletions aws/spring-cloud-aws-s3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions aws/spring-cloud-aws-s3/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
15 changes: 15 additions & 0 deletions aws/spring-cloud-aws-s3/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM maven:3.9-amazoncorretto-21 as backend
WORKDIR /backend
COPY pom.xml .
COPY lombok.config .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn clean install -DskipITs
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM openjdk:21
ARG DEPENDENCY=/backend/target/dependency
COPY --from=backend ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=backend ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=backend ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java", "-cp", "app:app/lib/*", "io.reflectoring.Application"]
26 changes: 26 additions & 0 deletions aws/spring-cloud-aws-s3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Interacting with Amazon S3 Bucket using Spring Cloud AWS

Codebase demonstrating connection and interaction with provisioned Amazon S3 bucket using [Spring Cloud AWS](https://spring.io/projects/spring-cloud-aws).

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`.

To run the application locally without provisioning actual AWS Resources, execute the below commands:

```bash
chmod +x localstack/init-s3-bucket.sh
```

```bash
sudo docker-compose build
```

```bash
sudo docker-compose up -d
```

## Blog posts

Blog posts about this topic:

* [Using Amazon S3 with Spring Cloud AWS](https://reflectoring.io/spring-cloud-aws-s3/)
* [Using AWS S3 Presigned URLs in Spring Boot](https://reflectoring.io/aws-s3-presigned-url-spring-boot/)
37 changes: 37 additions & 0 deletions aws/spring-cloud-aws-s3/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.7'

services:
localstack:
container_name: localstack
image: localstack/localstack:3.3
ports:
- 4566:4566
environment:
- SERVICES=s3
volumes:
- ./localstack/init-s3-bucket.sh:/etc/localstack/init/ready.d/init-s3-bucket.sh
networks:
- reflectoring

backend:
container_name: backend-application
build:
context: ./
dockerfile: Dockerfile
ports:
- 8080:8080
depends_on:
- localstack
environment:
spring.cloud.aws.s3.endpoint: 'http://localstack:4566'
spring.cloud.aws.s3.path-style-access-enabled: true
spring.cloud.aws.credentials.access-key: test
spring.cloud.aws.credentials.secret-key: test
spring.cloud.aws.s3.region: 'us-east-1'
io.reflectoring.aws.s3.bucket-name: 'reflectoring-bucket'
io.reflectoring.aws.s3.presigned-url.validity: 120
networks:
- reflectoring

networks:
reflectoring:
7 changes: 7 additions & 0 deletions aws/spring-cloud-aws-s3/localstack/init-s3-bucket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
bucket_name="reflectoring-bucket"

awslocal s3api create-bucket --bucket $bucket_name

echo "S3 bucket '$bucket_name' created successfully"
echo "Executed init-s3-bucket.sh"
1 change: 1 addition & 0 deletions aws/spring-cloud-aws-s3/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.nonNull.exceptionType=IllegalArgumentException
Loading

0 comments on commit 4f4387b

Please sign in to comment.