Skip to content

UCHE2022/ecommerce-app-deploy-project

Repository files navigation

Handson Microservice-XRay-AppMesh

1 - Setup Microservice

  • start with productapp and paymentapp taskdefinition
cd 1-Setup
aws ecs register-task-definition  --cli-input-json file://td-productapp-setup.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-paymentapp-setup.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-frontendapp.json --region us-west-2
  • create ECS service for both, productapp and paymentapp both without public URL assignment and without LB
  • grab URLs (host:port) of both services and set it in the td-frontendapp.json taskdefinition, environment variables
  • create taskdefinition for frontendappapp (the frontend)
aws ecs register-task-definition  --cli-input-json file://td-frontendapp-setup.json --region us-west-2
  • create frontendapp service
  • grab public URL of frontendapp ALB Url and make some requests

2 - Adding tracing with AWS XRay and logging with AWS CloudWatch

Extend role ecsTaskRole by attaching policy AWSXRayDaemonWriteAccess

Updating the task definitions to add xray-daemon sidecar container and additional env properties.

cd 2-Tracing-Logging
aws ecs register-task-definition  --cli-input-json file://td-productapp-tracing.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-paymentapp-tracing.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-frontendapp-tracing.json --region us-west-2

Ensure to update the final IP addresses of the product- / payment-app within the frontendapp taskdefinition, section environment variables

To apply all the changes, redeploy the corresponding ECS service and select the latest revision of the task definition.

3 - Adding service discovery

changes to our setup

  • productapp and paymentapp PORT 80, instead of 9001/9002
  • adjust security groups "productsvc" and "paymentsvc" to allow port 80
  • adjust frontendapp task definition to replace the product_HOST and payment_HOST env variables by the DNS names of the corresponding services, productsvc.ecs-course.local and paymentsvc.ecs-course.local
  • apply the changed task definitions
  • delete existing services for product- , and paymentsvc
  • recreate service for product- , and paymentsvc including service discovery
  • redeploy the frontendapp service with latest revision

Service discovery details

  • namespace: ecs-course.local
  • service discovery services: productsvc and paymentsvc

apply task definitions

cd 3-ServiceDiscovery
aws ecs register-task-definition  --cli-input-json file://td-productapp-servicediscovery.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-paymentapp-servicediscovery.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-frontendapp-servicediscovery.json --region us-west-2

4 - Adding AppMesh

extend TaskExecutionRole

attach policy AWSAppMeshEnvoyAccess

create AppMesh resources

  • open AWS mgm console, AppMesh service
  • click Create Mesh
  • provide name frontendapp-mesh and click button Create mesh
  • create AppMesh components
aws cloudformation create-stack --stack-name appmesh-resources --template-body file://./mesh-resources.yaml

adjust ECS services

frontendapp service

Taskdefinition

  • change to networking mode awsvpc and launchtype FARGATE
  • ensure env variables for product and payment hosts match their service discovery names product-service.ecs-course.local and payment-service.ecs-course.local
  • delete environment variable AWS_XRAY_DAEMON_ADDRESS
  • delete Links entry xray-daemon (this is no longer required in network mode awsvpc)
  • enable AppMesh integration by clicking checkbox Enable App Mesh integration
    • select frontendapp as application container name
    • select frontendapp-mesh as Mesh name
    • select frontendapp-service-vn as Virtual node name
    • click Apply !
    • click Confirm
  • in Container definitions, open the envoy container
    • add environment variable ENABLE_ENVOY_XRAY_TRACING with value 1
    • enable Cloudwatch logging
  • click on Create to create the new task definition revision

ECS service

  • delete existing ECS service frontendappsvc
  • delete listener 9000 in ALB
  • create new service
    • add to loadbalancer, new listener port 9000, new target group frontendappsvc
    • click Enable service discovery integration
    • select the existing namespace ecs-course.local
    • create new service discovery service frontendapp-service

product service

Taskdefinition

  • move to Fargate launchtype (to avoid the limitation of ENIs on our t2.small EC2 instance) by switching from EC2 to Fargate in Requires compatibilities
  • set Task memory to 1GB
  • set Task CPU to 0.5vCPU
  • enable AppMesh integration by clicking checkbox Enable App Mesh integration
    • select productapp as application container name
    • select frontendapp-mesh as Mesh name
    • select product-service-vn as Virtual node name
    • click Apply !
    • click Confirm
  • in Container definitions, open the envoy container
    • add environment variable ENABLE_ENVOY_XRAY_TRACING with value 1
    • enable Cloudwatch logging
  • click on Create to create the new task definition revision

ECS service

  • recreate ECS service
  • create new security group, open port 80 from everywhere
  • click Enable service discovery integration
    • select existing namespace
    • select existing service discovery service
    • select product-service
  • click Next step
  • click Next step
  • click Create service

payment service

Taskdefinition

  • enable AppMesh integration by clicking checkbox Enable App Mesh integration
    • select paymentapp as application container name
    • select frontendapp-mesh as Mesh name
    • select payment-service-vn as Virtual node name
    • click Apply !
    • click Confirm
  • in Container definitions, open the envoy container
    • add environment variable ENABLE_ENVOY_XRAY_TRACING with value 1
    • enable Cloudwatch logging
  • click on Create to create the new task definition revision

apply task definitions

cd 4-AppMesh
aws ecs register-task-definition  --cli-input-json file://td-productapp-appmesh.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-paymentapp-appmesh.json --region us-west-2
aws ecs register-task-definition  --cli-input-json file://td-frontendapp-appmesh.json --region us-west-2

export CORE_STACK_NAME="ecs-course-core-infrastructure"

ecs-cli up
--subnets subnet-06620e92772d7d0bc, subnet-0558b5109de70d1b3
--vpc vpc-0aad0e33a58c19a14
--launch-type EC2
--size 1 --instance-type t2.small
--cluster ecs-ec2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published