Utilizzare ListAccounts con un o AWS SDK CLI - Esempi di codice dell'AWS SDK

Ci sono altri AWS SDK esempi disponibili nel repository AWS Doc SDK Examples GitHub .

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à.

Utilizzare ListAccounts con un o AWS SDK CLI

I seguenti esempi di codice mostrano come utilizzareListAccounts.

.NET
AWS SDK for .NET
Nota

C'è altro su GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Uses the AWS Organizations service to list the accounts associated /// with the default account. /// </summary> public class ListAccounts { /// <summary> /// Creates the Organizations client and then calls its /// ListAccountsAsync method. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var request = new ListAccountsRequest { MaxResults = 5, }; var response = new ListAccountsResponse(); try { do { response = await client.ListAccountsAsync(request); response.Accounts.ForEach(a => DisplayAccounts(a)); if (response.NextToken is not null) { request.NextToken = response.NextToken; } } while (response.NextToken is not null); } catch (AWSOrganizationsNotInUseException ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Displays information about an Organizations account. /// </summary> /// <param name="account">An Organizations account for which to display /// information on the console.</param> private static void DisplayAccounts(Account account) { string accountInfo = $"{account.Id} {account.Name}\t{account.Status}"; Console.WriteLine(accountInfo); } }
CLI
AWS CLI

Per recuperare un elenco di tutti gli account di un'organizzazione

L'esempio seguente mostra come richiedere un elenco degli account di un'organizzazione:

aws organizations list-accounts

L'output include un elenco di oggetti di riepilogo degli account.

{ "Accounts": [ { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/111111111111", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481830215.45, "Id": "111111111111", "Name": "Master Account", "Email": "bill@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/222222222222", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835741.044, "Id": "222222222222", "Name": "Production Account", "Email": "alice@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/333333333333", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835795.536, "Id": "333333333333", "Name": "Development Account", "Email": "juan@example.com", "Status": "ACTIVE" }, { "Arn": "arn:aws:organizations::111111111111:account/o-exampleorgid/444444444444", "JoinedMethod": "INVITED", "JoinedTimestamp": 1481835812.143, "Id": "444444444444", "Name": "Test Account", "Email": "anika@example.com", "Status": "ACTIVE" } ] }
  • Per API i dettagli, vedere ListAccountsin AWS CLI Command Reference.