Create ECS Service

  1. Also in the Task interface just created, we will create an ECS service to run the newly created Task definition.
  • Select Deploy
  • Select Create Service

 Microservices with AWS Fargate

  1. Setup environment
  • Select cluster (Cluster-STACK_NAME)

 Microservices with AWS Fargate

  1. Configure Deployment
  • Application type, default Service
  • Name the Service name
  • Desired tasks, select 1

 Microservices with AWS Fargate

  1. Configure Network
  • VPC, select Mysfits-STACK_NAME
  • Subnets, select private subnets
  • For Security group, select Use an existing security group
  • Select the security group workshop67-fcaj-FargateContainerSecurityGroup-SFP7Slg2FV2i
  • Select Deploy

 Microservices with AWS Fargate

  1. Configure Load Balancing
  • Select Application Load Balancer
  • Select Use an existing load balancer
  • Select alb-STACK_NAME
  • Configure Listener (Port: 8080 and Protocol: HTTP)
  • Create Target group, enter microservice-tg
  • Health check path, enter /
  • Health check grace period, enter 300

 Microservices with AWS Fargate  Microservices with AWS Fargate

  1. Thus, we have successfully created and deployed the service.

 Microservices with AWS Fargate

  1. After the Microservice service is deployed, we check the website interface and perform a test like.

 Microservices with AWS Fargate

  1. We use the browser to access the website. Recheck the CloudWatch logs and it should display “Like processed.”

 Microservices with AWS Fargate

  1. Remove the endpoint from the monolith using VSCode.
  • In the monolith folder, open mythicalMysfitsService.py and find the following code:
# increment the number of likes for the provided mysfit.
@app.route("/mysfits/<mysfit_id>/like", methods=['POST'])
def likeMysfit(mysfit_id):
    serviceResponse = mysfitsTableClient.likeMysfit(mysfit_id)
    process_like_request()
    flaskResponse = Response(serviceResponse)
    flaskResponse.headers["Content-Type"] = "application/json"
    return flaskResponse

You can delete or comment out the code.

Microservices with AWS Fargate

  1. After that, we rebuild the monolith image
cd ~/environment/amazon-ecs-mythicalmysfits-workshop/workshop-1/app/monolith-service 
docker build -t monolith-service:nolike2 .

Microservices with AWS Fargate

  1. Perform tag assignment and push to the monolith ECR repository.
  • We use the tag: nolike2.
docker tag monolith-service:nolike2 $MONO_ECR_REPOSITORY_URI:nolike2
docker push $MONO_ECR_REPOSITORY_URI:nolike2

 Microservices with AWS Fargate

  1. Check the monolith repository on ECR, we will see the image pushed with the tag nolike2.

 Microservices with AWS Fargate

  1. Now, create a final Task Definition for the monolith to reference this Container Image URI and update the monolith service to use the new Task Definition and ensure the application still works as before.