Esempi di App Mesh utilizzando AWS CLI - AWS Command Line Interface

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Esempi di App Mesh utilizzando AWS CLI

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando AWS Command Line Interface with App Mesh.

Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le azioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Azioni

Il seguente esempio di codice mostra come utilizzarecreate-mesh.

AWS CLI

Esempio 1: come creare una nuova mesh di servizi

L’esempio create-mesh seguente crea una mesh di servizi.

aws appmesh create-mesh \ --mesh-name app1

Output:

{ "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" } } }

Esempio 2: come creare una nuova mesh di servizi con più tag

L’esempio create-mesh seguente crea una mesh di servizi con più tag.

aws appmesh create-mesh \ --mesh-name app2 \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3

Output:

{ "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" } } }

Per ulteriori informazioni, consulta Mesh dei servizi nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarecreate-route.

AWS CLI

Come creare una nuova route gRPC

L’esempio create-route seguente utilizza un file di input JSON per creare una route gRPC. Il traffico GRPC con metadati che iniziano con 123 viene instradato a un nodo virtuale denominato serviceBgrpc. Se durante il tentativo di comunicare con la destinazione della route si verificano errori gRPC, HTTP o TCP specifici, il tentativo di instradamento viene ripetuto tre volte, con un ritardo di 15 secondi tra ogni tentativo.

aws appmesh create-route \ --cli-input-json file://create-route-grpc.json

Contenuto di 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" } }

Come creare una nuova route HTTP o HTTP/2

L’esempio create-route seguente utilizza un file di input JSON per creare una route HTTP/2. Per creare una route HTTP, sostituisci http2Route con httpRoute in base alle specifiche. Tutto il traffico HTTP/2 indirizzato a qualsiasi prefisso URL con un valore di intestazione che inizia con 123 viene instradato verso un nodo virtuale denominato serviceBhttp2. Se durante il tentativo di comunicare con la destinazione della route si verificano errori HTTP o TCP specifici, il tentativo di instradamento viene ripetuto tre volte, con un ritardo di 15 secondi tra ogni tentativo.

aws appmesh create-route \ --cli-input-json file://create-route-http2.json

Contenuto di 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" } }

Come creare una nuova route TCP

L’esempio create-route seguente utilizza un file di input JSON per creare una route TCP. Il 75% del traffico viene instradato verso un nodo virtuale denominato serviceBtcp e il 25% verso un nodo virtuale denominato serviceBv2tcp. Specificare ponderazioni diverse per obiettivi differenti è un modo efficace per implementare una nuova versione di un’applicazione. È possibile modificare i pesi in modo che alla fine il 100% di tutto il traffico venga instradato verso una destinazione che dispone della nuova versione di un’applicazione.

aws appmesh create-route \ --cli-input-json file://create-route-tcp.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Route nella Guida per l’utente di AWS App Mesh.

  • Per i dettagli sull'API, consulta AWS CLI Command CreateRouteReference.

Il seguente esempio di codice mostra come utilizzarecreate-virtual-gateway.

AWS CLI

Come creare un nuovo gateway virtuale

L’esempio create-virtual-gateway seguente utilizza un file di input JSON per creare un gateway virtuale con un listener per HTTP sulla porta 9080.

aws appmesh create-virtual-gateway \ --mesh-name meshName \ --virtual-gateway-name virtualGatewayName \ --cli-input-json file://create-virtual-gateway.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Gateway virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarecreate-virtual-node.

AWS CLI

Esempio 1: come creare un nuovo nodo virtuale che utilizza DNS per il rilevamento

L’esempio create-virtual-node seguente utilizza un file di input JSON per creare un nodo virtuale che utilizza DNS per il rilevamento servizi.

aws appmesh create-virtual-node \ --cli-input-json file://create-virtual-node-dns.json

Contenuto di 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" } }

Esempio 2: creare un nuovo nodo virtuale che utilizza AWS Cloud Map per il rilevamento

L'create-virtual-nodeesempio seguente utilizza un file di input JSON per creare un nodo virtuale che utilizza AWS Cloud Map per il rilevamento dei servizi.

aws appmesh create-virtual-node \ --cli-input-json file://create-virtual-node-cloud-map.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Nodi virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarecreate-virtual-router.

AWS CLI

Come creare un nuovo router virtuale

L’esempio create-virtual-router seguente utilizza un file di input JSON per creare un router virtuale con un listener per HTTP sulla porta 80.

aws appmesh create-virtual-router \ --cli-input-json file://create-virtual-router.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Router virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarecreate-virtual-service.

AWS CLI

Esempio 1: come creare un nuovo servizio virtuale con un provider di nodi virtuali

L’esempio create-virtual-service seguente utilizza un file di input JSON per creare un servizio virtuale con un provider di nodi virtuali.

aws appmesh create-virtual-service \ --cli-input-json file://create-virtual-service-virtual-node.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Nodo virtuale nella Guida per l’utente di AWS App Mesh.

Esempio 2: come creare un nuovo servizio virtuale con un provider di router virtuali

L’esempio create-virtual-service seguente utilizza un file di input JSON per creare un servizio virtuale con un provider di router virtuali.

aws appmesh create-virtual-service \ --cli-input-json file://create-virtual-service-virtual-router.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Virtual Services< https://docs.aws.amazon.com/app-mesh/ latest/userguide/virtual _services.html> nella App Mesh User Guide AWS

Il seguente esempio di codice mostra come utilizzaredelete-mesh.

AWS CLI

Come eliminare una mesh di servizi

L’esempio delete-mesh seguente elimina la mesh di servizi specificata.

aws appmesh delete-mesh \ --mesh-name app1

Output:

{ "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" } } }

Per ulteriori informazioni, consulta Mesh dei servizi nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredelete-route.

AWS CLI

Come eliminare una route

L’esempio delete-route seguente elimina la route specificata.

aws appmesh delete-route \ --mesh-name app1 \ --virtual-router-name vrServiceB \ --route-name toVnServiceB-weighted

Output:

{ "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" } }

Per ulteriori informazioni, consulta Route nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredelete-virtual-node.

AWS CLI

Come eliminare un nodo virtuale

L’esempio delete-virtual-node seguente elimina il nodo virtuale specificato.

aws appmesh delete-virtual-node \ --mesh-name app1 \ --virtual-node-name vnServiceBv2

Output:

{ "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" } }

Per ulteriori informazioni, consulta Nodi virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredelete-virtual-router.

AWS CLI

Come eliminare un router virtuale

L’esempio delete-virtual-router seguente elimina il router virtuale specificato.

aws appmesh delete-virtual-router \ --mesh-name app1 \ --virtual-router-name vrServiceB

Output:

{ "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" } }

Per ulteriori informazioni, consulta Router virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredelete-virtual-service.

AWS CLI

Come eliminare un servizio virtuale

L’esempio delete-virtual-service seguente elimina il servizio virtuale specificato.

aws appmesh delete-virtual-service \ --mesh-name app1 \ --virtual-service-name 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": 1563913940.866, "uid": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "version": 3 }, "spec": {}, "status": { "status": "DELETED" }, "virtualServiceName": "serviceB.svc.cluster.local" } }

Per ulteriori informazioni, consulta Servizio virtuale nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredescribe-mesh.

AWS CLI

Come descrivere una mesh di servizi

L’esempio describe-mesh seguente restituisce i dettagli della mesh di servizi specificata.

aws appmesh describe-mesh \ --mesh-name app1

Output:

{ "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" } } }

Per ulteriori informazioni, consulta Mesh dei servizi nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredescribe-route.

AWS CLI

Come descrivere una route

L’esempio describe-route seguente restituisce i dettagli della route specificata.

aws appmesh describe-route \ --mesh-name app1 \ --virtual-router-name vrServiceB \ --route-name toVnServiceB-weighted

Output:

{ "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" } }

Per ulteriori informazioni, consulta Route nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredescribe-virtual-node.

AWS CLI

Come descrivere un nodo virtuale

L’esempio describe-virtual-node seguente restituisce i dettagli del nodo virtuale specificato.

aws appmesh describe-virtual-node \ --mesh-name app1 \ --virtual-node-name 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": { "backends": [], "listeners": [ { "portMapping": { "port": 80, "protocol": "http" } } ], "serviceDiscovery": { "dns": { "hostname": "serviceBv1.svc.cluster.local" } } }, "status": { "status": "ACTIVE" }, "virtualNodeName": "vnServiceBv1" } }

Per ulteriori informazioni, consulta Nodi virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredescribe-virtual-router.

AWS CLI

Come descrivere un router virtuale

L’esempio describe-virtual-router seguente restituisce i dettagli del router virtuale specificato.

aws appmesh describe-virtual-router \ --mesh-name app1 \ --virtual-router-name 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" } }

Per ulteriori informazioni, consulta Router virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaredescribe-virtual-service.

AWS CLI

Come descrivere un servizio virtuale

L’esempio describe-virtual-service seguente restituisce i dettagli del servizio virtuale specificato.

aws appmesh describe-virtual-service \ --mesh-name app1 \ --virtual-service-name 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" } }

Per ulteriori informazioni, consulta Servizio virtuale nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarelist-meshes.

AWS CLI

Come elencare le mesh di servizi

L'list-meshesesempio seguente elenca tutte le mesh di servizio nella AWS regione corrente.

aws appmesh list-meshes

Output:

{ "meshes": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1", "meshName": "app1" } ] }

Per ulteriori informazioni, consulta Mesh dei servizi nella Guida per l’utente di AWS App Mesh.

  • Per i dettagli sull'API, vedere ListMeshesin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzarelist-routes.

AWS CLI

Come elencare le route

L’esempio list-routes seguente elenca tutte le route del router virtuale specificato.

aws appmesh list-routes \ --mesh-name app1 \ --virtual-router-name vrServiceB

Output:

{ "routes": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB/route/toVnServiceB", "meshName": "app1", "routeName": "toVnServiceB-weighted", "virtualRouterName": "vrServiceB" } ] }

Per ulteriori informazioni, consulta Route nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarelist-tags-for-resource.

AWS CLI

Come elencare i tag per una risorsa

L’esempio list-tags-for-resource seguente elenca tutti i tag assegnati alla risorsa specificata.

aws appmesh list-tags-for-resource \ --resource-arn arn:aws:appmesh:us-east-1:123456789012:mesh/app1

Output:

{ "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ] }

Il seguente esempio di codice mostra come utilizzarelist-virtual-nodes.

AWS CLI

Come elencare i nodi virtuali

L’esempio list-virtual-nodes seguente elenca tutti i nodi virtuali della mesh di servizi specificata.

aws appmesh list-virtual-nodes \ --mesh-name app1

Output:

{ "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" } ] }

Per ulteriori informazioni, consulta Nodi virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarelist-virtual-routers.

AWS CLI

Come elencare i router virtuali

L’esempio list-virtual-routers seguente elenca tutti i router virtuali nella mesh di servizi specificata.

aws appmesh list-virtual-routers \ --mesh-name app1

Output:

{ "virtualRouters": [ { "arn": "arn:aws:appmesh:us-east-1:123456789012:mesh/app1/virtualRouter/vrServiceB", "meshName": "app1", "virtualRouterName": "vrServiceB" } ] }

Per ulteriori informazioni, consulta Router virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzarelist-virtual-services.

AWS CLI

Come elencare i servizi virtuali

L’esempio list-virtual-services seguente elenca tutti i servizi virtuali nella mesh di servizi specificata.

aws appmesh list-virtual-services \ --mesh-name app1

Output:

{ "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" } ] }

Per ulteriori informazioni, consulta Servizio virtuale nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzaretag-resource.

AWS CLI

Come taggare a una risorsa

L’esempio tag-resource seguente aggiunge il tag key1 con il valore value1 alla risorsa specificata.

aws appmesh tag-resource \ --resource-arn arn:aws:appmesh:us-east-1:123456789012:mesh/app1 \ --tags key=key1,value=value1

Questo comando non produce alcun output.

Il seguente esempio di codice mostra come utilizzareuntag-resource.

AWS CLI

Come rimuovere un tag da una risorsa

L’esempio untag-resource seguente rimuove un tag con la chiave key1 dalla risorsa specificata.

aws appmesh untag-resource \ --resource-arn arn:aws:appmesh:us-east-1:123456789012:mesh/app1 \ --tag-keys key1

Questo comando non produce alcun output.

Il seguente esempio di codice mostra come utilizzareupdate-mesh.

AWS CLI

Come aggiornare una mesh di servizi

L’esempio update-mesh seguente utilizza un file di input JSON per aggiornare una mesh di servizi per consentire l’inoltro inalterato di tutto il traffico esterno in uscita attraverso il proxy Envoy.

aws appmesh update-mesh \ --cli-input-json file://update-mesh.json

Contenuto di 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" } } }

Per ulteriori informazioni, consulta Mesh dei servizi nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzareupdate-route.

AWS CLI

Come aggiornare una route

L’esempio update-route seguente utilizza un file di input JSON per aggiornare i pesi di una route.

aws appmesh update-route \ --cli-input-json file://update-route-weighted.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Route nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzareupdate-virtual-node.

AWS CLI

Come aggiornare un nodo virtuale

L’esempio update-virtual-node seguente utilizza un file di input JSON per aggiungere un controllo dell’integrità a un nodo virtuale.

aws appmesh update-virtual-node \ --cli-input-json file://update-virtual-node.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Nodi virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzareupdate-virtual-router.

AWS CLI

Come aggiornare un router virtuale

L’esempio update-virtual-router seguente utilizza un file di input JSON per aggiornare la porta listener di un router virtuale.

aws appmesh update-virtual-router \ --cli-input-json file://update-virtual-router.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Router virtuali nella Guida per l’utente di AWS App Mesh.

Il seguente esempio di codice mostra come utilizzareupdate-virtual-service.

AWS CLI

Come aggiornare un servizio virtuale

L’esempio update-virtual-service seguente utilizza un file di input JSON per aggiornare un servizio virtuale in modo che utilizzi un provider di router virtuali.

aws appmesh update-virtual-service \ --cli-input-json file://update-virtual-service.json

Contenuto di 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" } }

Per ulteriori informazioni, consulta Servizio virtuale nella Guida per l’utente di AWS App Mesh.