Esempi per Network Flow Monitor con AWS CLI - AWS Command Line Interface

Esempi per Network Flow Monitor con AWS CLI

L’esempio di codice seguente mostra come eseguire operazioni e implementare scenari comuni utilizzando AWS Command Line Interface con Network Flow Monitor.

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

Ogni esempio include un link al codice sorgente completo, dove è possibile trovare le istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Operazioni

L’esempio di codice seguente mostra come utilizzare create-monitor.

AWS CLI

Come creare un monitoraggio

Nell’esempio seguente create-monitor crea un monitoraggio denominato demo nell’account specificato.

aws networkflowmonitor create-monitor \ --monitor-name demo \ --local-resources type="AWS::EC2::VPC",identifier="arn:aws:ec2:us-east-1:123456789012:vpc/vpc-03ea55eeda25adbb0" \ --scope-arn arn:aws:networkflowmonitor:us-east-1:123456789012:scope/e21cda79-30a0-4c12-9299-d8629d76d8cf

Output:

{ "monitorArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/demo", "monitorName": "demo", "monitorStatus": "ACTIVE", "tags": {} }

Per ulteriori informazioni, consulta Create a monitor in Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta CreateMonitor in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare create-scope.

AWS CLI

Come creare un ambito

Nell’esempio seguente create-scope crea un ambito che include un set di risorse per le quali Network Flow Monitor genererà delle metriche del traffico di rete.

aws networkflowmonitor create-scope \ --targets '[{"targetIdentifier":{"targetId":{"accountId":"123456789012"},"targetType":"ACCOUNT"},"region":"us-east-1"}]'

Output:

{ "scopeId": "97626f8d-8a21-4b5d-813a-1a0962dd4615", "status": "IN_PROGRESS", "tags": {} }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta CreateScope in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare delete-monitor.

AWS CLI

Come eliminare un monitor

Nell’esempio seguente delete-monitor elimina un monitor denominato demo nell’account specificato.

aws networkflowmonitor delete-monitor \ --monitor-name demo

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Delete a monitor in Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta DeleteMonitor in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare delete-scope.

AWS CLI

Come eliminare un ambito

Nell’esempio seguente delete-scope elimina un ambito specificato.

aws networkflowmonitor delete-scope \ --scope-id fdc20616-6bb4-4242-a24e-a748e65ca7ac

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per ulteriori informazioni sull’API, consulta DeleteScope in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare get-monitor.

AWS CLI

Come recuperare le informazioni relative a un monitor

Nell’esempio seguente get-monitor visualizza le informazioni sul monitor denominato demo nell’account specificato.

aws networkflowmonitor get-monitor \ --monitor-name Demo

Output:

{ "monitorArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo", "monitorName": "Demo", "monitorStatus": "ACTIVE", "localResources": [ { "type": "AWS::EC2::VPC", "identifier": "arn:aws:ec2:us-east-1:123456789012:vpc/vpc-03ea55eeda25adbb0" } ], "remoteResources": [], "createdAt": "2024-12-09T12:21:51.616000-06:00", "modifiedAt": "2024-12-09T12:21:55.412000-06:00", "tags": {} }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta GetMonitor in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare get-query-results-workload-insights-top-contributors-data.

AWS CLI

Come recuperare i dati dei principali contributor sulle informazioni dettagliate relative al carico di lavoro

Nell’esempio seguente get-query-results-workload-insights-top-contributors-data restituisce i dati per la query specificata.

aws networkflowmonitor get-query-results-workload-insights-top-contributors-data \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id cc4f4ab3-3103-33b8-80ff-d6597a0c6cea

Output:

{ "datapoints": [ { "timestamps": [ "2024-12-09T19:00:00+00:00", "2024-12-09T19:05:00+00:00", "2024-12-09T19:10:00+00:00" ], "values": [ 259943.0, 194856.0, 216432.0 ], "label": "use1-az6" } ], "unit": "Bytes" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare get-query-results-workload-insights-top-contributors.

AWS CLI

Come recuperare i principali contributor sulle informazioni dettagliate relative al carico di lavoro

Nell’esempio seguente get-query-results-workload-insights-top-contributors restituisce i dati per la query specificata.

aws networkflowmonitor get-query-results-workload-insights-top-contributors \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id 1fc423d3-b144-37a6-80e6-e2c7d26eea0c

Output:

{ "topContributors": [ { "accountId": "123456789012", "localSubnetId": "subnet-0a5b30fb95dca2c14", "localAz": "use1-az6", "localVpcId": "vpc-03ea55eeda25adbb0", "localRegion": "us-east-1", "remoteIdentifier": "", "value": 908443, "localSubnetArn": "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-0a5b30fb95dca2c14", "localVpcArn": "arn:aws:ec2:us-east-1:123456789012:vpc/vpc-03ea55eeda25adbb0" } ] }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare get-query-status-monitor-top-contributors.

AWS CLI

Come recuperare lo stato della query

Nell’esempio seguente get-query-status-monitor-top-contributors visualizza lo stato corrente della query nell’account specificato.

aws networkflowmonitor get-query-status-monitor-top-contributors \ --monitor-name Demo \ --query-id 5398eabd-bc40-3f5f-aba3-bcb639d3c7ca

Output:

{ "status": "SUCCEEDED" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare get-query-status-workload-insights-top-contributors-data.

AWS CLI

Come recuperare lo stato della query

Nell’esempio seguente get-query-status-workload-insights-top-contributors-data visualizza lo stato corrente della query nell’account specificato.

aws networkflowmonitor get-query-status-workload-insights-top-contributors-data \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id 4333754d-8ae1-3f29-b6b7-c36db2e7f8ac

Output:

{ "status": "SUCCEEDED" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare get-query-status-workload-insights-top-contributors.

AWS CLI

Come recuperare lo stato della query

Nell’esempio seguente get-query-status-workload-insights-top-contributors visualizza lo stato corrente della query nell’account specificato.

aws networkflowmonitor get-query-status-workload-insights-top-contributors \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id f2a87c70-3e5a-362e-8beb-4747d13d8419

Output:

{ "status": "SUCCEEDED" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare get-scope.

AWS CLI

Come recuperare le informazioni relative a un ambito

Nell’esempio seguente get-scope mostra informazioni su un ambito, come lo stato, i tag, il nome e i dettagli di destinazione.

aws networkflowmonitor get-scope \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf

Output:

{ "scopeId": "e21cda79-30a0-4c12-9299-d8629d76d8cf", "status": "SUCCEEDED", "scopeArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/e21cda79-30a0-4c12-9299-d8629d76d8cf", "targets": [ { "targetIdentifier": { "targetId": { "accountId": "123456789012" }, "targetType": "ACCOUNT" }, "region": "us-east-1" } ], "tags": {} }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta GetScope in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare list-monitors.

AWS CLI

Come recuperare un elenco di monitor

Nell’elenco seguente list-monitors restituisce tutti i monitor dell’account specificato.

aws networkflowmonitor list-monitors

Output:

{ "monitors": [ { "monitorArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo", "monitorName": "Demo", "monitorStatus": "ACTIVE" } ] }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta ListMonitors in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare list-scopes.

AWS CLI

Come recuperare un elenco di ambiti

Nell’esempio seguente list-scopes elenca tutti gli ambiti nell’account specificato.

aws networkflowmonitor list-scopes

Output:

{ "scopes": [ { "scopeId": "fdc20616-6bb4-4242-a24e-a748e65ca7ac", "status": "SUCCEEDED", "scopeArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:scope/fdc20616-6bb4-4242-a24e-a748e65ca7ac" } ] }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta ListScopes in AWS CLI Command Reference.

L’esempio di codice seguente mostra come utilizzare list-tags-for-resource.

AWS CLI

Come elencare i tag

Nell’esempio seguente, list-tags-for-resource restituisce tutti i tag associati alla risorsa specificata.

aws networkflowmonitor list-tags-for-resource \ --resource-arn arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo

Output:

{ "tags": { "Value": "Production", "Key": "stack" } }

Per ulteriori informazioni, consulta Tagging your Amazon CloudWatch resources nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull'API, consulta ListTagsForResource nella Documentazione di riferimento dei comandi della AWS CLI.

L’esempio di codice seguente mostra come utilizzare start-query-monitor-top-contributors.

AWS CLI

Come avviare una query

Nell’esempio seguente start-query-monitor-top-contributors avvia la query che restituisce un ID di query per recuperare i principali contributor.

aws networkflowmonitor start-query-monitor-top-contributors \ --monitor-name Demo \ --start-time 2024-12-09T19:00:00Z \ --end-time 2024-12-09T19:15:00Z \ --metric-name DATA_TRANSFERRED \ --destination-category UNCLASSIFIED

Output:

{ "queryId": "aecd3a88-0283-35b0-a17d-6e944dc8531d" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare start-query-workload-insights-top-contributors-data.

AWS CLI

Come avviare una query

Nell’esempio seguente start-query-workload-insights-top-contributors-data avvia la query che restituisce un ID di query per recuperare i principali contributor.

aws networkflowmonitor start-query-workload-insights-top-contributors-data \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --start-time 2024-12-09T19:00:00Z \ --end-time 2024-12-09T19:15:00Z \ --metric-name DATA_TRANSFERRED \ --destination-category UNCLASSIFIED

Output:

{ "queryId": "cc4f4ab3-3103-33b8-80ff-d6597a0c6cea" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare start-query-workload-insights-top-contributors.

AWS CLI

Come avviare una query

Nell’esempio seguente start-query-workload-insights-top-contributors avvia la query che restituisce un ID di query per recuperare i principali contributor.

aws networkflowmonitor start-query-workload-insights-top-contributors \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --start-time 2024-12-09T19:00:00Z \ --end-time 2024-12-09T19:15:00Z \ --metric-name DATA_TRANSFERRED \ --destination-category UNCLASSIFIED

Output:

{ "queryId": "1fc423d3-b144-37a6-80e6-e2c7d26eea0c" }

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare stop-query-monitor-top-contributors.

AWS CLI

Come interrompere una query

Nell’esempio seguente, stop-query-monitor-top-contributors interrompe la query nell’account specificato.

aws networkflowmonitor stop-query-monitor-top-contributors \ --monitor-name Demo \ --query-id aecd3a88-0283-35b0-a17d-6e944dc8531d

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare stop-query-workload-insights-top-contributors-data.

AWS CLI

Come interrompere una query

Nell’esempio seguente, stop-query-workload-insights-top-contributors-data interrompe la query nell’account specificato.

aws networkflowmonitor stop-query-workload-insights-top-contributors-data \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id cc4f4ab3-3103-33b8-80ff-d6597a0c6cea

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare stop-query-workload-insights-top-contributors.

AWS CLI

Come interrompere una query

Nell’esempio seguente, stop-query-workload-insights-top-contributors interrompe la query nell’account specificato.

aws networkflowmonitor stop-query-workload-insights-top-contributors \ --scope-id e21cda79-30a0-4c12-9299-d8629d76d8cf \ --query-id 1fc423d3-b144-37a6-80e6-e2c7d26eea0c

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Evaluate network flows with workload insights nella Guida per l’utente di Amazon CloudWatch.

L’esempio di codice seguente mostra come utilizzare tag-resource.

AWS CLI

Come aggiungere un tag alla risorsa specificata

Nell’esempio seguente tag-resource aggiunge un tag al monitor nell’account specificato.

aws networkflowmonitor tag-resource \ --resource-arn arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo \ --tags Key=stack,Value=Production

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Tagging your Amazon CloudWatch resources nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sulle API, consulta TagResource nel Riferimento ai comandi AWS CLI.

L’esempio di codice seguente mostra come utilizzare untag-resource.

AWS CLI

Come rimuovere tutti i tag dalla risorsa specificata

Nell’esempio seguente untag-resource rimuove un tag dal monitor nell’account specificato.

aws networkflowmonitor untag-resource \ --resource-arn arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo \ --tag-keys stack

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Tagging your Amazon CloudWatch resources nella Guida per l’utente di Amazon CloudWatch.

  • Per i dettagli dell'API, consulta UntagResource in Riferimento ai comandi della AWS CLI.

L’esempio di codice seguente mostra come utilizzare update-monitor.

AWS CLI

Come aggiornare un monitor esistente

Nell’esempio seguente update-monitor aggiorna il monitor denominato Demo nell’account specificato.

aws networkflowmonitor update-monitor \ --monitor-name Demo \ --local-resources-to-add type="AWS::EC2::VPC",identifier="arn:aws:ec2:us-east-1:123456789012:vpc/vpc-048d08dfbec623f94"

Output:

{ "monitorArn": "arn:aws:networkflowmonitor:us-east-1:123456789012:monitor/Demo", "monitorName": "Demo", "monitorStatus": "ACTIVE", "tags": { "Value": "Production", "Key": "stack" } }

Per ulteriori informazioni, consulta Components and features of Network Flow Monitor nella Guida per l’utente di Amazon CloudWatch.

  • Per informazioni dettagliate sull’API, consulta UpdateMonitor in AWS CLI Command Reference.