Describe database - Amazon Timestream

Describe database

You can use the following code snippets to get information about the attributes of your newly created database.

Note

These code snippets are based on full sample applications on GitHub. For more information about how to get started with the sample applications, see Sample application.

Java
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = new DescribeDatabaseRequest(); describeDatabaseRequest.setDatabaseName(DATABASE_NAME); try { DescribeDatabaseResult result = amazonTimestreamWrite.describeDatabase(describeDatabaseRequest); final Database databaseRecord = result.getDatabase(); final String databaseId = databaseRecord.getArn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
Java v2
public void describeDatabase() { System.out.println("Describing database"); final DescribeDatabaseRequest describeDatabaseRequest = DescribeDatabaseRequest.builder() .databaseName(DATABASE_NAME).build(); try { DescribeDatabaseResponse response = timestreamWriteClient.describeDatabase(describeDatabaseRequest); final Database databaseRecord = response.database(); final String databaseId = databaseRecord.arn(); System.out.println("Database " + DATABASE_NAME + " has id " + databaseId); } catch (final Exception e) { System.out.println("Database doesn't exist = " + e); throw e; } }
Go
describeDatabaseOutput, err := writeSvc.DescribeDatabase(describeDatabaseInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Describe database is successful, below is the output:") fmt.Println(describeDatabaseOutput) }
Python
def describe_database(self): print("Describing database") try: result = self.client.describe_database(DatabaseName=Constant.DATABASE_NAME) print("Database [%s] has id [%s]" % (Constant.DATABASE_NAME, result['Database']['Arn'])) except self.client.exceptions.ResourceNotFoundException: print("Database doesn't exist") except Exception as err: print("Describe database failed:", err)
Node.js

The following snippet uses AWS SDK for JavaScript v3. For more information about how to install the client and usage, see Timestream Write Client - AWS SDK for JavaScript v3.

Also see Class DescribeDatabaseCommand and DescribeDatabase.

import { TimestreamWriteClient, DescribeDatabaseCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode" }; const command = new DescribeDatabaseCommand(params); try { const data = await writeClient.send(command); console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); } catch (error) { if (error.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", error); throw error; } }

The following snippet uses the AWS SDK for JavaScript V2 style. It is based on the sample application at Node.js sample Amazon Timestream for LiveAnalytics application on GitHub.

async function describeDatabase () { console.log("Describing Database"); const params = { DatabaseName: constants.DATABASE_NAME }; const promise = writeClient.describeDatabase(params).promise(); await promise.then( (data) => { console.log(`Database ${data.Database.DatabaseName} has id ${data.Database.Arn}`); }, (err) => { if (err.code === 'ResourceNotFoundException') { console.log("Database doesn't exist."); } else { console.log("Describe database failed.", err); throw err; } } ); }
.NET
public async Task DescribeDatabase() { Console.WriteLine("Describing Database"); try { var describeDatabaseRequest = new DescribeDatabaseRequest { DatabaseName = Constants.DATABASE_NAME }; DescribeDatabaseResponse response = await writeClient.DescribeDatabaseAsync(describeDatabaseRequest); Console.WriteLine($"Database {Constants.DATABASE_NAME} has id:{response.Database.Arn}"); } catch (ResourceNotFoundException) { Console.WriteLine("Database does not exist."); } catch (Exception e) { Console.WriteLine("Describe database failed:" + e.ToString()); } }