This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
App Mesh examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with App Mesh.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use create-mesh.
- Amazon CLI
 - 
             
                    
Example 1: To create a new service mesh
The following
create-meshexample creates a service mesh.aws appmesh create-mesh \ --mesh-nameapp1Output:
{ "mesh":{ "meshName":"app1", "metadata":{ "arn":"arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "createdAt":1563809909.282, "lastUpdatedAt":1563809909.282, "uid":"a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version":1 }, "spec":{}, "status":{ "status":"ACTIVE" } } }Example 2: To create a new service mesh with multiple tags
The following
create-meshexample creates a service mesh with multiple tags.aws appmesh create-mesh \ --mesh-nameapp2\ --tagskey=key1,value=value1key=key2,value=value2key=key3,value=value3Output:
{ "mesh":{ "meshName":"app2", "metadata":{ "arn":"arn:aws:appmesh:us-east-1:123456789012:mesh/app2", "createdAt":1563822121.877, "lastUpdatedAt":1563822121.877, "uid":"a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version":1 }, "spec":{}, "status":{ "status":"ACTIVE" } } }For more information, see Service Meshes
in the Amazon App Mesh User Guide. - 
                    
For API details, see CreateMesh
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use create-route.
- Amazon CLI
 - 
             
                    
To create a new gRPC route
The following
create-routeexample uses a JSON input file to create a gRPC route. GRPC traffic that has metadata that starts with 123 is routed to a virtual node named serviceBgrpc. If there are specific gRPC, HTTP, or TCP failures when attempting to communicate with the target of the route, the route is retried three times. There is a 15 second delay between each retry attempt.aws appmesh create-route \ --cli-input-jsonfile://create-route-grpc.jsonContents of
create-route-grpc.json:{ "meshName" : "apps", "routeName" : "grpcRoute", "spec" : { "grpcRoute" : { "action" : { "weightedTargets" : [ { "virtualNode" : "serviceBgrpc", "weight" : 100 } ] }, "match" : { "metadata" : [ { "invert" : false, "match" : { "prefix" : "123" }, "name" : "myMetadata" } ], "methodName" : "GetColor", "serviceName" : "com.amazonaws.services.ColorService" }, "retryPolicy" : { "grpcRetryEvents" : [ "deadline-exceeded" ], "httpRetryEvents" : [ "server-error", "gateway-error" ], "maxRetries" : 3, "perRetryTimeout" : { "unit" : "s", "value" : 15 }, "tcpRetryEvents" : [ "connection-error" ] } }, "priority" : 100 }, "virtualRouterName" : "serviceBgrpc" }Output:
{ "route": { "meshName": "apps", "metadata": { "arn": "arn:aws:appmesh:us-west-2:123456789012:mesh/apps/virtualRouter/serviceBgrpc/route/grpcRoute", "createdAt": 1572010806.008, "lastUpdatedAt": 1572010806.008, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "routeName": "grpcRoute", "spec": { "grpcRoute": { "action": { "weightedTargets": [ { "virtualNode": "serviceBgrpc", "weight": 100 } ] }, "match": { "metadata": [ { "invert": false, "match": { "prefix": "123" }, "name": "mymetadata" } ], "methodName": "GetColor", "serviceName": "com.amazonaws.services.ColorService" }, "retryPolicy": { "grpcRetryEvents": [ "deadline-exceeded" ], "httpRetryEvents": [ "server-error", "gateway-error" ], "maxRetries": 3, "perRetryTimeout": { "unit": "s", "value": 15 }, "tcpRetryEvents": [ "connection-error" ] } }, "priority": 100 }, "status": { "status": "ACTIVE" }, "virtualRouterName": "serviceBgrpc" } }To create a new HTTP or HTTP/2 route
The following
create-routeexample uses a JSON input file to create an HTTP/2 route. To create an HTTP route, replace http2Route with httpRoute under spec. All HTTP/2 traffic addressed to any URL prefix that has a header value that starts with 123 is routed to a virtual node named serviceBhttp2. If there are specific HTTP or TCP failures when attempting to communicate with the target of the route, the route is retried three times. There is a 15 second delay between each retry attempt.aws appmesh create-route \ --cli-input-jsonfile://create-route-http2.jsonContents of
create-route-http2.json:{ "meshName": "apps", "routeName": "http2Route", "spec": { "http2Route": { "action": { "weightedTargets": [ { "virtualNode": "serviceBhttp2", "weight": 100 } ] }, "match": { "headers": [ { "invert": false, "match": { "prefix": "123" }, "name": "clientRequestId" } ], "method": "POST", "prefix": "/", "scheme": "http" }, "retryPolicy": { "httpRetryEvents": [ "server-error", "gateway-error" ], "maxRetries": 3, "perRetryTimeout": { "unit": "s", "value": 15 }, "tcpRetryEvents": [ "connection-error" ] } }, "priority": 200 }, "virtualRouterName": "serviceBhttp2" }Output:
{ "route": { "meshName": "apps", "metadata": { "arn": "arn:aws:appmesh:us-west-2:123456789012:mesh/apps/virtualRouter/serviceBhttp2/route/http2Route", "createdAt": 1572011008.352, "lastUpdatedAt": 1572011008.352, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "routeName": "http2Route", "spec": { "http2Route": { "action": { "weightedTargets": [ { "virtualNode": "serviceBhttp2", "weight": 100 } ] }, "match": { "headers": [ { "invert": false, "match": { "prefix": "123" }, "name": "clientRequestId" } ], "method": "POST", "prefix": "/", "scheme": "http" }, "retryPolicy": { "httpRetryEvents": [ "server-error", "gateway-error" ], "maxRetries": 3, "perRetryTimeout": { "unit": "s", "value": 15 }, "tcpRetryEvents": [ "connection-error" ] } }, "priority": 200 }, "status": { "status": "ACTIVE" }, "virtualRouterName": "serviceBhttp2" } }To create a new TCP route
The following
create-routeexample uses a JSON input file to create a TCP route. 75 percent of traffic is routed to a virtual node named serviceBtcp, and 25 percent of traffic is routed to a virtual node named serviceBv2tcp. Specifying different weightings for different targets is an effective way to do a deployment of a new version of an application. You can adjust the weights so that eventually, 100 percent of all traffic is routed to a target that has the new version of an application.aws appmesh create-route \ --cli-input-jsonfile://create-route-tcp.jsonContents of create-route-tcp.json:
{ "meshName": "apps", "routeName": "tcpRoute", "spec": { "priority": 300, "tcpRoute": { "action": { "weightedTargets": [ { "virtualNode": "serviceBtcp", "weight": 75 }, { "virtualNode": "serviceBv2tcp", "weight": 25 } ] } } }, "virtualRouterName": "serviceBtcp" }Output:
{ "route": { "meshName": "apps", "metadata": { "arn": "arn:aws:appmesh:us-west-2:123456789012:mesh/apps/virtualRouter/serviceBtcp/route/tcpRoute", "createdAt": 1572011436.26, "lastUpdatedAt": 1572011436.26, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "routeName": "tcpRoute", "spec": { "priority": 300, "tcpRoute": { "action": { "weightedTargets": [ { "virtualNode": "serviceBtcp", "weight": 75 }, { "virtualNode": "serviceBv2tcp", "weight": 25 } ] } } }, "status": { "status": "ACTIVE" }, "virtualRouterName": "serviceBtcp" } }For more information, see Routes
in the Amazon App Mesh User Guide. - 
                    
For API details, see CreateRoute
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use create-virtual-gateway.
- Amazon CLI
 - 
             
                    
To create a new virtual gateway
The following
create-virtual-gatewayexample uses a JSON input file to create a virtual gateway with a listener for HTTP using port 9080.aws appmesh create-virtual-gateway \ --mesh-namemeshName\ --virtual-gateway-namevirtualGatewayName\ --cli-input-jsonfile://create-virtual-gateway.jsonContents of
create-virtual-gateway.json:{ "spec": { "listeners": [ { "portMapping": { "port": 9080, "protocol": "http" } } ] } }Output:
{ "virtualGateway": { "meshName": "meshName", "metadata": { "arn": "arn:aws:appmesh:us-west-2:123456789012:mesh/meshName/virtualGateway/virtualGatewayName", "createdAt": "2022-04-06T10:42:42.015000-05:00", "lastUpdatedAt": "2022-04-06T10:42:42.015000-05:00", "meshOwner": "123456789012", "resourceOwner": "123456789012", "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "listeners": [ { "portMapping": { "port": 9080, "protocol": "http" } } ] }, "status": { "status": "ACTIVE" }, "virtualGatewayName": "virtualGatewayName" } }For more information, see Virtual Gateways
in the Amazon App Mesh User Guide. - 
                    
For API details, see CreateVirtualGateway
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use create-virtual-node.
- Amazon CLI
 - 
             
                    
Example 1: To create a new virtual node that uses DNS for discovery
The following
create-virtual-nodeexample uses a JSON input file to create a virtual node that uses DNS for service discovery.aws appmesh create-virtual-node \ --cli-input-jsonfile://create-virtual-node-dns.jsonContents of
create-virtual-node-dns.json:{ "meshName": "app1", "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "virtualNodeName": "vnServiceBv1" }Output:
{ "virtualNode": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv1", "createdAt": 1563810019.874, "lastUpdatedAt": 1563810019.874, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "status": { "status": "ACTIVE" }, "virtualNodeName": "vnServiceBv1" } }Example 2: To create a new virtual node that uses Amazon Cloud Map for discovery
The following
create-virtual-nodeexample uses a JSON input file to create a virtual node that uses Amazon Cloud Map for service discovery.aws appmesh create-virtual-node \ --cli-input-jsonfile://create-virtual-node-cloud-map.jsonContents of
create-virtual-node-cloud-map.json:{ "meshName": "app1", "spec": { "backends": [ { "virtualService": { "virtualServiceName": "serviceA.svc.cluster.local" } } ], "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "awsCloudMap": { "attributes": [ { "key": "Environment", "value": "Testing" } ], "namespaceName": "namespace1", "serviceName": "serviceA" } } }, "virtualNodeName": "vnServiceA" }Output:
{ "virtualNode": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceA", "createdAt": 1563810859.465, "lastUpdatedAt": 1563810859.465, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "backends": [ { "virtualService": { "virtualServiceName": "serviceA.svc.cluster.local" } } ], "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "awsCloudMap": { "attributes": [ { "key": "Environment", "value": "Testing" } ], "namespaceName": "namespace1", "serviceName": "serviceA" } } }, "status": { "status": "ACTIVE" }, "virtualNodeName": "vnServiceA" } }For more information, see Virtual Nodes
in the Amazon App Mesh User Guide. - 
                    
For API details, see CreateVirtualNode
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use create-virtual-router.
- Amazon CLI
 - 
             
                    
To create a new virtual router
The following
create-virtual-routerexample uses a JSON input file to create a virtual router with a listener for HTTP using port 80.aws appmesh create-virtual-router \ --cli-input-jsonfile://create-virtual-router.jsonContents of
create-virtual-router.json:{ "meshName": "app1", "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ] }, "virtualRouterName": "vrServiceB" }Output:
{ "virtualRouter": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "createdAt": 1563810546.59, "lastUpdatedAt": 1563810546.59, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ] }, "status": { "status": "ACTIVE" }, "virtualRouterName": "vrServiceB" } }For more information, see Virtual Routers
in the Amazon App Mesh User Guide. - 
                    
For API details, see CreateVirtualRouter
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use create-virtual-service.
- Amazon CLI
 - 
             
                    
Example 1: To create a new virtual service with a virtual node provider
The following
create-virtual-serviceexample uses a JSON input file to create a virtual service with a virtual node provider.aws appmesh create-virtual-service \ --cli-input-jsonfile://create-virtual-service-virtual-node.jsonContents of
create-virtual-service-virtual-node.json:{ "meshName": "app1", "spec": { "provider": { "virtualNode": { "virtualNodeName": "vnServiceA" } } }, "virtualServiceName": "serviceA.svc.cluster.local" }Output:
{ "virtualService": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceA.svc.cluster.local", "createdAt": 1563810859.474, "lastUpdatedAt": 1563810967.179, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "provider": { "virtualNode": { "virtualNodeName": "vnServiceA" } } }, "status": { "status": "ACTIVE" }, "virtualServiceName": "serviceA.svc.cluster.local" } }For more information, see Virtual Node
in the Amazon App Mesh User Guide. Example 2: To create a new virtual service with a virtual router provider
The following
create-virtual-serviceexample uses a JSON input file to create a virtual service with a virtual router provider.aws appmesh create-virtual-service \ --cli-input-jsonfile://create-virtual-service-virtual-router.jsonContents of
create-virtual-service-virtual-router.json:{ "meshName": "app1", "spec": { "provider": { "virtualRouter": { "virtualRouterName": "vrServiceB" } } }, "virtualServiceName": "serviceB.svc.cluster.local" }Output:
{ "virtualService": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceB.svc.cluster.local", "createdAt": 1563908363.999, "lastUpdatedAt": 1563908363.999, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "provider": { "virtualRouter": { "virtualRouterName": "vrServiceB" } } }, "status": { "status": "ACTIVE" }, "virtualServiceName": "serviceB.svc.cluster.local" } }For more information, see Virtual Services<https://docs.aws.amazon.com/app-mesh/latest/userguide/virtual_services.html> in the Amazon App Mesh User Guide
- 
                    
For API details, see CreateVirtualService
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use delete-mesh.
- Amazon CLI
 - 
             
                    
To delete a service mesh
The following
delete-meshexample deletes the specified service mesh.aws appmesh delete-mesh \ --mesh-nameapp1Output:
{ "mesh": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "createdAt": 1563809909.282, "lastUpdatedAt": 1563824981.248, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "egressFilter": { "type": "ALLOW_ALL" } }, "status": { "status": "DELETED" } } }For more information, see Service Meshes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DeleteMesh
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use delete-route.
- Amazon CLI
 - 
             
                    
To delete a route
The following
delete-routeexample deletes the specified route.aws appmesh delete-route \ --mesh-nameapp1\ --virtual-router-namevrServiceB\ --route-nametoVnServiceB-weightedOutput:
{ "route": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB/route/toVnServiceB-weighted", "createdAt": 1563811384.015, "lastUpdatedAt": 1563823915.936, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 3 }, "routeName": "toVnServiceB-weighted", "spec": { "httpRoute": { "action": { "weightedTargets": [ { "virtualNode": "vnServiceBv1", "weight": 80 }, { "virtualNode": "vnServiceBv2", "weight": 20 } ] }, "match": { "prefix": "/" } } }, "status": { "status": "DELETED" }, "virtualRouterName": "vrServiceB" } }For more information, see Routes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DeleteRoute
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use delete-virtual-node.
- Amazon CLI
 - 
             
                    
To delete a virtual node
The following
delete-virtual-nodeexample deletes the specified virtual node.aws appmesh delete-virtual-node \ --mesh-nameapp1\ --virtual-node-namevnServiceBv2Output:
{ "virtualNode": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv2", "createdAt": 1563810117.297, "lastUpdatedAt": 1563824700.678, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "backends": [], "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv2.svc.cluster.local" } } }, "status": { "status": "DELETED" }, "virtualNodeName": "vnServiceBv2" } }For more information, see Virtual Nodes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DeleteVirtualNode
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use delete-virtual-router.
- Amazon CLI
 - 
             
                    
To delete a virtual router
The following
delete-virtual-routerexample deletes the specified virtual router.aws appmesh delete-virtual-router \ --mesh-nameapp1\ --virtual-router-namevrServiceBOutput:
{ "virtualRouter": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "createdAt": 1563810546.59, "lastUpdatedAt": 1563824253.467, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 3 }, "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ] }, "status": { "status": "DELETED" }, "virtualRouterName": "vrServiceB" } }For more information, see Virtual Routers
in the Amazon App Mesh User Guide. - 
                    
For API details, see DeleteVirtualRouter
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use delete-virtual-service.
- Amazon CLI
 - 
             
                    
To delete a virtual service
The following
delete-virtual-serviceexample deletes the specified virtual service.aws appmesh delete-virtual-service \ --mesh-nameapp1\ --virtual-service-nameserviceB.svc.cluster.localOutput:
{ "virtualService": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceB.svc.cluster.local", "createdAt": 1563908363.999, "lastUpdatedAt": 1563913940.866, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 3 }, "spec": {}, "status": { "status": "DELETED" }, "virtualServiceName": "serviceB.svc.cluster.local" } }For more information, see Virtual Service
in the Amazon App Mesh User Guide. - 
                    
For API details, see DeleteVirtualService
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use describe-mesh.
- Amazon CLI
 - 
             
                    
To describe a service mesh
The following
describe-meshexample returns details about the specified service mesh.aws appmesh describe-mesh \ --mesh-nameapp1Output:
{ "mesh": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "createdAt": 1563809909.282, "lastUpdatedAt": 1563809909.282, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": {}, "status": { "status": "ACTIVE" } } }For more information, see Service Meshes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DescribeMesh
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use describe-route.
- Amazon CLI
 - 
             
                    
To describe a route
The following
describe-routeexample returns details about the specified route.aws appmesh describe-route \ --mesh-nameapp1\ --virtual-router-namevrServiceB\ --route-nametoVnServiceB-weightedOutput:
{ "route": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB/route/toVnServiceB-weighted", "createdAt": 1563811384.015, "lastUpdatedAt": 1563811384.015, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "routeName": "toVnServiceB-weighted", "spec": { "httpRoute": { "action": { "weightedTargets": [ { "virtualNode": "vnServiceBv1", "weight": 90 }, { "virtualNode": "vnServiceBv2", "weight": 10 } ] }, "match": { "prefix": "/" } } }, "status": { "status": "ACTIVE" }, "virtualRouterName": "vrServiceB" } }For more information, see Routes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DescribeRoute
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use describe-virtual-node.
- Amazon CLI
 - 
             
                    
To describe a virtual node
The following
describe-virtual-nodeexample returns details about the specified virtual node.aws appmesh describe-virtual-node \ --mesh-nameapp1\ --virtual-node-namevnServiceBv1Output:
{ "virtualNode": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv1", "createdAt": 1563810019.874, "lastUpdatedAt": 1563810019.874, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "backends": [], "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "status": { "status": "ACTIVE" }, "virtualNodeName": "vnServiceBv1" } }For more information, see Virtual Nodes
in the Amazon App Mesh User Guide. - 
                    
For API details, see DescribeVirtualNode
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use describe-virtual-router.
- Amazon CLI
 - 
             
                    
To describe a virtual router
The following
describe-virtual-routerexample returns details about the specified virtual router.aws appmesh describe-virtual-router \ --mesh-nameapp1\ --virtual-router-namevrServiceBOutput:
{ "virtualRouter": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "createdAt": 1563810546.59, "lastUpdatedAt": 1563810546.59, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ] }, "status": { "status": "ACTIVE" }, "virtualRouterName": "vrServiceB" } }For more information, see Virtual Routers
in the Amazon App Mesh User Guide. - 
                    
For API details, see DescribeVirtualRouter
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use describe-virtual-service.
- Amazon CLI
 - 
             
                    
To describe a virtual service
The following
describe-virtual-serviceexample returns details about the specified virtual service.aws appmesh describe-virtual-service \ --mesh-nameapp1\ --virtual-service-nameserviceB.svc.cluster.localOutput:
{ "virtualService": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceB.svc.cluster.local", "createdAt": 1563908363.999, "lastUpdatedAt": 1563908363.999, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 1 }, "spec": { "provider": { "virtualRouter": { "virtualRouterName": "vrServiceB" } } }, "status": { "status": "ACTIVE" }, "virtualServiceName": "serviceB.svc.cluster.local" } }For more information, see Virtual Services
in the Amazon App Mesh User Guide. - 
                    
For API details, see DescribeVirtualService
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-meshes.
- Amazon CLI
 - 
             
                    
To list service meshes
The following
list-meshesexample lists all of the service meshes in the current Amazon Region.aws appmesh list-meshesOutput:
{ "meshes": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "meshName": "app1" } ] }For more information, see Service Meshes
in the Amazon App Mesh User Guide. - 
                    
For API details, see ListMeshes
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-routes.
- Amazon CLI
 - 
             
                    
To list routes
The following
list-routesexample lists all of the routes for the specified virtual router.aws appmesh list-routes \ --mesh-nameapp1\ --virtual-router-namevrServiceBOutput:
{ "routes": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB/route/toVnServiceB", "meshName": "app1", "routeName": "toVnServiceB-weighted", "virtualRouterName": "vrServiceB" } ] }For more information, see Routes
in the Amazon App Mesh User Guide. - 
                    
For API details, see ListRoutes
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-tags-for-resource.
- Amazon CLI
 - 
             
                    
To list tags for a resource
The following
list-tags-for-resourceexample lists all of the tags assigned to the specified resource.aws appmesh list-tags-for-resource \ --resource-arnarn:aws:appmesh:us-east-1:123456789012:mesh/app1Output:
{ "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ] }- 
                    
For API details, see ListTagsForResource
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-virtual-nodes.
- Amazon CLI
 - 
             
                    
To list virtual nodes
The following
list-virtual-nodesexample lists all of the virtual nodes in the specified service mesh.aws appmesh list-virtual-nodes \ --mesh-nameapp1Output:
{ "virtualNodes": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv1", "meshName": "app1", "virtualNodeName": "vnServiceBv1" }, { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv2", "meshName": "app1", "virtualNodeName": "vnServiceBv2" } ] }For more information, see Virtual Nodes
in the Amazon App Mesh User Guide. - 
                    
For API details, see ListVirtualNodes
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-virtual-routers.
- Amazon CLI
 - 
             
                    
To list virtual routers
The following
list-virtual-routersexample lists all of the virtual routers in the specified service mesh.aws appmesh list-virtual-routers \ --mesh-nameapp1Output:
{ "virtualRouters": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "meshName": "app1", "virtualRouterName": "vrServiceB" } ] }For more information, see Virtual Routers
in the Amazon App Mesh User Guide. - 
                    
For API details, see ListVirtualRouters
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use list-virtual-services.
- Amazon CLI
 - 
             
                    
To list virtual services
The following
list-virtual-servicesexample lists all of the virtual services in the specified service mesh.aws appmesh list-virtual-services \ --mesh-nameapp1Output:
{ "virtualServices": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceA.svc.cluster.local", "meshName": "app1", "virtualServiceName": "serviceA.svc.cluster.local" }, { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceB.svc.cluster.local", "meshName": "app1", "virtualServiceName": "serviceB.svc.cluster.local" } ] }For more information, see Virtual Services
in the Amazon App Mesh User Guide. - 
                    
For API details, see ListVirtualServices
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use tag-resource.
- Amazon CLI
 - 
             
                    
To tag a resource
The following
tag-resourceexample adds the tagkey1with the valuevalue1to the specified resource.aws appmesh tag-resource \ --resource-arnarn:aws:appmesh:us-east-1:123456789012:mesh/app1\ --tagskey=key1,value=value1This command produces no output.
- 
                    
For API details, see TagResource
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use untag-resource.
- Amazon CLI
 - 
             
                    
To untag a resource
The following
untag-resourceexample removes a tag with the keykey1from the specified resource.aws appmesh untag-resource \ --resource-arnarn:aws:appmesh:us-east-1:123456789012:mesh/app1\ --tag-keyskey1This command produces no output.
- 
                    
For API details, see UntagResource
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use update-mesh.
- Amazon CLI
 - 
             
                    
To update a service mesh
The following
update-meshexample uses a JSON input file to update a service mesh to allow all external egress traffic to be forwarded through the Envoy proxy untouched.aws appmesh update-mesh \ --cli-input-jsonfile://update-mesh.jsonContents of
update-mesh.json:{ "meshName": "app1", "spec": { "egressFilter": { "type": "ALLOW_ALL" } } }Output:
{ "mesh": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "createdAt": 1563809909.282, "lastUpdatedAt": 1563812829.687, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "egressFilter": { "type": "ALLOW_ALL" } }, "status": { "status": "ACTIVE" } } }For more information, see Service Meshes
in the Amazon App Mesh User Guide. - 
                    
For API details, see UpdateMesh
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use update-route.
- Amazon CLI
 - 
             
                    
To update a route
The following
update-routeexample uses a JSON input file to update the weights for a route.aws appmesh update-route \ --cli-input-jsonfile://update-route-weighted.jsonContents of
update-route-weighted.json:{ "meshName": "app1", "routeName": "toVnServiceB-weighted", "spec": { "httpRoute": { "action": { "weightedTargets": [ { "virtualNode": "vnServiceBv1", "weight": 80 }, { "virtualNode": "vnServiceBv2", "weight": 20 } ] }, "match": { "prefix": "/" } } }, "virtualRouterName": "vrServiceB" }Output:
{ "route": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB/route/toVnServiceB-weighted", "createdAt": 1563811384.015, "lastUpdatedAt": 1563819600.022, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "routeName": "toVnServiceB-weighted", "spec": { "httpRoute": { "action": { "weightedTargets": [ { "virtualNode": "vnServiceBv1", "weight": 80 }, { "virtualNode": "vnServiceBv2", "weight": 20 } ] }, "match": { "prefix": "/" } } }, "status": { "status": "ACTIVE" }, "virtualRouterName": "vrServiceB" } }For more information, see Routes
in the Amazon App Mesh User Guide. - 
                    
For API details, see UpdateRoute
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use update-virtual-node.
- Amazon CLI
 - 
             
                    
To update a virtual node
The following
update-virtual-nodeexample uses a JSON input file to add a health check to a virtual node.aws appmesh update-virtual-node \ --cli-input-jsonfile://update-virtual-node.jsonContents of
update-virtual-node.json:{ "clientToken": "500", "meshName": "app1", "spec": { "listeners": [ { "healthCheck": { "healthyThreshold": 5, "intervalMillis": 10000, "path": "/", "port": 80, "protocol": "http", "timeoutMillis": 3000, "unhealthyThreshold": 3 }, "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "virtualNodeName": "vnServiceBv1" }Output:
{ "virtualNode": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualNode/vnServiceBv1", "createdAt": 1563810019.874, "lastUpdatedAt": 1563819234.825, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "listeners": [ { "healthCheck": { "healthyThreshold": 5, "intervalMillis": 10000, "path": "/", "port": 80, "protocol": "http", "timeoutMillis": 3000, "unhealthyThreshold": 3 }, "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "status": { "status": "ACTIVE" }, "virtualNodeName": "vnServiceBv1" } }For more information, see Virtual Nodes
in the Amazon App Mesh User Guide. - 
                    
For API details, see UpdateVirtualNode
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use update-virtual-router.
- Amazon CLI
 - 
             
                    
To update a virtual router
The following
update-virtual-routerexample uses a JSON input file to update a virtual router listener port.aws appmesh update-virtual-router \ --cli-input-jsonfile://update-virtual-router.jsonContents of
update-virtual-router.json:{ "meshName": "app1", "spec": { "listeners": [ { "portMapping": { "port": 8080, "protocol": "http" } } ] }, "virtualRouterName": "vrServiceB" }Output:
{ "virtualRouter": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "createdAt": 1563810546.59, "lastUpdatedAt": 1563819431.352, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 2 }, "spec": { "listeners": [ { "portMapping": { "port": 8080, "protocol": "http" } } ] }, "status": { "status": "ACTIVE" }, "virtualRouterName": "vrServiceB" } }For more information, see Virtual Routers
in the Amazon App Mesh User Guide. - 
                    
For API details, see UpdateVirtualRouter
in Amazon CLI Command Reference.  
 - 
                    
 
The following code example shows how to use update-virtual-service.
- Amazon CLI
 - 
             
                    
To update a virtual service
The following
update-virtual-serviceexample uses a JSON input file to update a virtual service to use a virtual router provider.aws appmesh update-virtual-service \ --cli-input-jsonfile://update-virtual-service.jsonContents of
update-virtual-service.json:{ "meshName": "app1", "spec": { "provider": { "virtualRouter": { "virtualRouterName": "vrServiceA" } } }, "virtualServiceName": "serviceA.svc.cluster.local" }Output:
{ "virtualService": { "meshName": "app1", "metadata": { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualService/serviceA.svc.cluster.local", "createdAt": 1563810859.474, "lastUpdatedAt": 1563820257.411, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 3 }, "spec": { "provider": { "virtualRouter": { "virtualRouterName": "vrServiceA" } } }, "status": { "status": "ACTIVE" }, "virtualServiceName": "serviceA.svc.cluster.local" } }For more information, see Virtual Services
in the Amazon App Mesh User Guide. - 
                    
For API details, see UpdateVirtualService
in Amazon CLI Command Reference.  
 -