Create a virtual router

Please note that this workshop has been archived and is not actively maintained. On September 30, 2026, AWS will discontinue support for AWS App Mesh. For more information, visit this blog post.

Virtual routers handle traffic for one or more virtual services within your mesh. We will create a virtual router and associate routes to direct incoming requests to the different virtual node destinations we have for the Crystal backend.

  • Begin by creating the virtual router.
# Define variables #
SPEC=$(cat <<-EOF
  { 
    "listeners": [
      {
        "portMapping": { "port": 3000, "protocol": "http" }
      }
    ]
  }
EOF
); \
# Create app mesh virtual router #
aws appmesh create-virtual-router \
  --mesh-name appmesh-workshop \
  --virtual-router-name crystal-router \
  --spec "$SPEC"
  • Create a route to shift the traffic to the new virtual node. For now, all traffic will be sent to the crystal-lb-vanilla virtual node. Once the crystal-sd-vanilla virutal node is fully operational, we will distribute between them at a 2:1 ratio (i.e., the crystal-sd-vanilla node will receive two thirds of the traffic).
# Define variables #
SPEC=$(cat <<-EOF
  { 
    "httpRoute": {
      "action": { 
        "weightedTargets": [
          {
            "virtualNode": "crystal-lb-vanilla",
            "weight": 1
          },
          {
            "virtualNode": "crystal-sd-vanilla",
            "weight": 0
          }
        ]
      },
      "match": {
        "prefix": "/"
      }
    },
    "priority": 10
  }
EOF
); \
# Create app mesh route #
aws appmesh create-route \
  --mesh-name appmesh-workshop \
  --virtual-router-name crystal-router \
  --route-name crystal-traffic-route \
  --spec "$SPEC"