Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ docker buildx build --platform linux/amd64,linux/arm64 \
.
```

| Language-Framework | App Directory | ECR Repo |
|--------------------|--------------------------|--------------|
| python-flask | docker-apps/python/flask | python-flask |
| Language-Framework | App Directory | ECR Repo |
|--------------------|------------------------------|-----------------|
| python-flask | docker-apps/python/flask | python-flask |
| java-springboot | docker-apps/java/spring-boot | java-springboot |

##### Deploy & Cleanup Containerized Infrastructure

Expand All @@ -67,6 +68,7 @@ cdk deploy <stack-name>
cdk destroy <stack-name>
```

| Language-Framework | Stack Name |
|--------------------|---------------------|
| python-flask | PythonFlaskCdkStack |
| Language-Framework | Stack Name |
|--------------------|------------------------|
| python-flask | PythonFlaskCdkStack |
| java-springboot | JavaSpringBootCdkStack |
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
## SPDX-License-Identifier: Apache-2.0

FROM public.ecr.aws/docker/library/maven:3.9-amazoncorretto-17 AS build

WORKDIR /app

COPY pom.xml .
RUN mvn dependency:go-offline

COPY src ./src
RUN mvn clean package -DskipTests

FROM public.ecr.aws/docker/library/amazoncorretto:17-alpine

RUN apk add --no-cache curl bash && \
addgroup -g 1001 -S appuser && \
adduser -u 1001 -S appuser -G appuser

WORKDIR /app

COPY --from=build /app/target/*.jar app.jar
COPY generate-traffic.sh .

RUN chmod +x generate-traffic.sh && \
chown -R appuser:appuser /app

USER appuser

ENV PORT=8080

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${PORT}/health || exit 1

CMD ["sh", "-c", "java ${JAVA_OPTS:--XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError} -jar app.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PORT=${PORT:-8080}
BASE_URL="http://localhost:${PORT}"

echo "Starting continuous traffic generation to ${BASE_URL}"

while true; do
echo "[$(date '+%H:%M:%S')] Generating traffic..."

curl -sf "${BASE_URL}/health" > /dev/null
if [ $? -ne 0 ]; then
echo "[$(date '+%H:%M:%S')] ERROR: Health check failed!"
fi

curl -sf "${BASE_URL}/api/buckets" > /dev/null
if [ $? -ne 0 ]; then
echo "[$(date '+%H:%M:%S')] ERROR: API call to /api/buckets failed!"
fi

sleep 2
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.application</groupId>
<artifactId>springboot-application</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Spring Boot Application</name>
<description>Spring Boot application for AWS Application Signals testing</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/>
</parent>

<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.20.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.application.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.application.springboot;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
public class Controller {
private static final Logger logger = LoggerFactory.getLogger(Controller.class);
private final S3Client s3Client;
private final ObjectMapper objectMapper;

public Controller() {
this.s3Client = S3Client.builder().build();
this.objectMapper = new ObjectMapper();
}

@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
public String index() throws Exception {
return healthCheck();
}

@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
public String healthCheck() throws Exception {
logger.info("Health check endpoint called");
Map<String, String> response = Map.of("status", "healthy");
return objectMapper.writeValueAsString(response) + "\n";
}

@GetMapping(value = "/api/buckets", produces = MediaType.APPLICATION_JSON_VALUE)
public String listBuckets() throws Exception {
try {
ListBucketsResponse response = s3Client.listBuckets();
List<String> buckets = response.buckets().stream()
.map(bucket -> bucket.name())
.collect(Collectors.toList());
logger.info("Successfully listed " + buckets.size() + " S3 buckets");
Map<String, Object> responseMap = Map.of(
"bucket_count", buckets.size(),
"buckets", buckets
);
return objectMapper.writeValueAsString(responseMap) + "\n";
} catch (Exception e) {
logger.error("Exception thrown when Listing Buckets: " + e.getMessage());
Map<String, String> errorResponse = Map.of("error", "Failed to retrieve S3 buckets");
return objectMapper.writeValueAsString(errorResponse) + "\n";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server.port=${PORT:8080}
logging.level.root=INFO
logging.level.com.example.springboot=INFO
Loading