- An example to setup microservices using fargate. We are going to setup two microservices:
- ItemsService: A simple Express.js based microservice that hosts a list of items.
- RatingsService: A simple Express.js based microservice that hosts ratings for the items.
Broadly:
- Two NodeJs microservices using AWS Fargate within a VPC we define.
- An application load balancer.
- AWS API Gateway integration backed by AWS Private Link.
Note: I have deployed this application to us-west-2
region. As such, the readme lists example outputs and commands for us-west-2
. If you would like to deploy this to any other region, alter the commands appropriately, update and replace code references from us-west-2
to your desired region.
- You have your favorite IDE installed for exploring code. (IntelliJ or VSCode)
- You have node and npm installed. I highly encourage using nvm for easy management of node versions.
- You have installed and configured
aws-cdk
. If not you can find the configuration instructions here. - You have installed and configured
aws-cli
. If not you can find the instructions here - You have docker installed, up and running.
- Follow readme instructions on ItemsService repository
- Follow readme instructions on RatingsService repository
- Login to ECR
aws ecr get-login-password --region <your_aws-region> | docker login --username AWS --password-stdin <aws_acc_id>.dkr.ecr.us-west-2.amazonaws.com
- If login was successful:
Login Succeeded
- Create
items-service
ECR repository
aws ecr create-repository \
--repository-name items-service \
--image-scanning-configuration scanOnPush=false \
--region us-west-2
- Your output should look like as follows:
{
"repository": {
"repositoryArn": "arn:aws:ecr:us-west-2:<aws_acc_id>:repository/items-service1",
"registryId": "<aws_acc_id>",
"repositoryName": "items-service",
"repositoryUri": "<aws_acc_id>.dkr.ecr.us-west-2.amazonaws.com/items-service1",
"createdAt": "<ISO Timestamp>",
"imageTagMutability": "MUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
}
}
- Create
ratings-service
ECR repository
aws ecr create-repository \
--repository-name ratings-service \
--image-scanning-configuration scanOnPush=false \
--region us-west-2
- Your output should look like as follows:
{
"repository": {
"repositoryArn": "arn:aws:ecr:us-west-2:<aws_acc_id>:repository/ratings-service",
"registryId": "<aws_acc_id>",
"repositoryName": "ratings-service",
"repositoryUri": "<aws_acc_id>.dkr.ecr.us-west-2.amazonaws.com/ratings-service",
"createdAt": "ISO Timestamp",
"imageTagMutability": "MUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
}
}
- Verify your images are listed in docker:
docker images
- Push items-service image to ECR:
docker push <aws_acc_id>.dkr.ecr.us-west2.amazonaws.com/items-service
- Push ratings-service image to ECR:
docker push <aws_acc_id>.dkr.ecr.us-west-2.amazonaws.com/ratings-service
Every time you make changes to your images or the infrastructure, you would want to run the following steps
npm run build
cdk bootstrap
(required only once)cdk synth
cdk deploy --all
ApiGatewayStack.EC2publicipaddress = x.x.x.x
ApiGatewayStack.HTTPAPIendpoint = https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com
ApiGatewayStack.ItemsService = https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/api/items
ApiGatewayStack.RatingsService = https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/api/ratings
Stack ARN:
arn:aws:cloudformation:us-west-2:<aws_acc_id>:stack/ApiGatewayStack/<uuid>
- You can access items and ratings services at the following:
- Update readme with dir structure and references
- Update architecture diagram