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.
# 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"
# 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"