Sample project to present the idea of Service Discovery on Amazon Elastic Container Service (ECS). Come and visit our blog for detailed information - Handling Amazon ECS Service Discovery in Java.
The project consists of two SpringBoot applications. If not specified, the instructions below can be used in both cases.
Docker engine (v19 or newer)
Java v11
SpringBoot v2.x
Gradle v6.4.x
The assumption is to run these applications on Amazon ECS, so the projects are packaged into Docker image.
Follow the steps to create Docker image and push it to Elastic Container Registry (ECR).
./gradlew clean build
docker build -t aws-pattern-match-textapi .
Notice: aws-pattern-match-textapi
is just an example name.
$(aws ecr get-login --no-include-email --region eu-west-1)
Notice: change the region to reflect your ECS setup
docker tag aws-pattern-match-textprocessor:latest xxxxxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/aws-pattern-match-textprocessor:latest
Notice: change the image name and ECR repo in accordance to your setup
docker push xxxxxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/aws-pattern-match-textprocessor:latest
Notice: change the image name and ECR repo in accordance to your setup
Notice: In the commands below, use the images in accordance to your setup.
docker run --env AWS_REGION=<your-region> --env AWS_DEFAULT_REGION=<your-region> --env AWS_ACCESS_KEY_ID=<your-aws-key-id> --env AWS_SECRET_ACCESS_KEY=<your-aws-key> -d -p 8090:8080 aws-pattern-match-textapi:latest
Request:
curl -X POST --header "Content-type: application/json" --header "Accept: application/json" -d '{"text": "somewhere over the rainbow skies are blue, clouds high over the rainbow, makes all your dreams come true"}' http://localhost:8090/textapi
Response:
{
"language": "en",
"sentiment": "POSITIVE"
}
docker run --env TEXTAPI_ENDPOINT=http://host.docker.internal:8090 -d -p 8091:8080 aws-pattern-match-textprocessor:latest
Notice: The env variable TEXTAPI_ENDPOINT
should point to the TextApi REST endpoint. Change the above command in accordance to your setup.
Request:
curl -X POST --header "Content-type: application/json" --header "Accept: application/json" -d '{"text": "somewhere over the rainbow skies are blue, clouds high over the rainbow, makes all your dreams come true"}' http://localhost:8091/textprocessor
Response:
{
"language": "en",
"sentiment": "POSITIVE"
}
Please check our blog post for detailed instructions.