데이터베이스 나열 - Amazon Timestream

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

데이터베이스 나열

다음 코드 조각을 사용하여 데이터베이스를 나열할 수 있습니다.

참고

이러한 코드 조각은 GitHub의 전체 샘플 애플리케이션을 기반으로 합니다. 샘플 애플리케이션을 시작하는 방법에 대한 자세한 내용은 섹션을 참조하세요샘플 애플리케이션.

Java
public void listDatabases() { System.out.println("Listing databases"); ListDatabasesRequest request = new ListDatabasesRequest(); ListDatabasesResult result = amazonTimestreamWrite.listDatabases(request); final List<Database> databases = result.getDatabases(); printDatabases(databases); String nextToken = result.getNextToken(); while (nextToken != null && !nextToken.isEmpty()) { request.setNextToken(nextToken); ListDatabasesResult nextResult = amazonTimestreamWrite.listDatabases(request); final List<Database> nextDatabases = nextResult.getDatabases(); printDatabases(nextDatabases); nextToken = nextResult.getNextToken(); } } private void printDatabases(List<Database> databases) { for (Database db : databases) { System.out.println(db.getDatabaseName()); } }
Java v2
public void listDatabases() { System.out.println("Listing databases"); ListDatabasesRequest request = ListDatabasesRequest.builder().maxResults(2).build(); ListDatabasesIterable listDatabasesIterable = timestreamWriteClient.listDatabasesPaginator(request); for(ListDatabasesResponse listDatabasesResponse : listDatabasesIterable) { final List<Database> databases = listDatabasesResponse.databases(); databases.forEach(database -> System.out.println(database.databaseName())); } }
Go
// List databases. listDatabasesMaxResult := int64(15) listDatabasesInput := &timestreamwrite.ListDatabasesInput{ MaxResults: &listDatabasesMaxResult, } listDatabasesOutput, err := writeSvc.ListDatabases(listDatabasesInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("List databases is successful, below is the output:") fmt.Println(listDatabasesOutput) }
Python
def list_databases(self): print("Listing databases") try: result = self.client.list_databases(MaxResults=5) self._print_databases(result['Databases']) next_token = result.get('NextToken', None) while next_token: result = self.client.list_databases(NextToken=next_token, MaxResults=5) self._print_databases(result['Databases']) next_token = result.get('NextToken', None) except Exception as err: print("List databases failed:", err)
Node.js

다음 코드 조각은 AWS SDK for JavaScript v3를 사용합니다. 클라이언트를 설치하는 방법과 사용량에 대한 자세한 내용은 Timestream Write Client - AWS SDK for JavaScript v3를 참조하세요.

Class ListDatabasesCommandListDatabases도 참조하세요.

import { TimestreamWriteClient, ListDatabasesCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { MaxResults: 15 }; const command = new ListDatabasesCommand(params); getDatabasesList(null); async function getDatabasesList(nextToken) { if (nextToken) { params.NextToken = nextToken; } try { const data = await writeClient.send(command); data.Databases.forEach(function (database) { console.log(database.DatabaseName); }); if (data.NextToken) { return getDatabasesList(data.NextToken); } } catch (error) { console.log("Error while listing databases", error); } }

다음 코드 조각은 AWS SDK for JavaScript V2 스타일을 사용합니다. 이는 Node.js 샘플 Amazon Timestream for LiveAnalytics GitHub.

async function listDatabases() { console.log("Listing databases:"); const databases = await getDatabasesList(null); databases.forEach(function(database){ console.log(database.DatabaseName); }); } function getDatabasesList(nextToken, databases = []) { var params = { MaxResults: 15 }; if(nextToken) { params.NextToken = nextToken; } return writeClient.listDatabases(params).promise() .then( (data) => { databases.push.apply(databases, data.Databases); if (data.NextToken) { return getDatabasesList(data.NextToken, databases); } else { return databases; } }, (err) => { console.log("Error while listing databases", err); }); }
.NET
public async Task ListDatabases() { Console.WriteLine("Listing Databases"); try { var listDatabasesRequest = new ListDatabasesRequest { MaxResults = 5 }; ListDatabasesResponse response = await writeClient.ListDatabasesAsync(listDatabasesRequest); PrintDatabases(response.Databases); var nextToken = response.NextToken; while (nextToken != null) { listDatabasesRequest.NextToken = nextToken; response = await writeClient.ListDatabasesAsync(listDatabasesRequest); PrintDatabases(response.Databases); nextToken = response.NextToken; } } catch (Exception e) { Console.WriteLine("List database failed:" + e.ToString()); } }