Update table
You can use the following code snippets to update a table.
Note
These code snippets are based on full sample applications on GitHub
- Java
-
public void updateTable() { System.out.println("Updating table"); UpdateTableRequest updateTableRequest = new UpdateTableRequest(); updateTableRequest.setDatabaseName(DATABASE_NAME); updateTableRequest.setTableName(TABLE_NAME); final RetentionProperties retentionProperties = new RetentionProperties() .withMemoryStoreRetentionPeriodInHours(HT_TTL_HOURS) .withMagneticStoreRetentionPeriodInDays(CT_TTL_DAYS); updateTableRequest.setRetentionProperties(retentionProperties); amazonTimestreamWrite.updateTable(updateTableRequest); System.out.println("Table updated"); }
- Java v2
-
public void updateTable() { System.out.println("Updating table"); final RetentionProperties retentionProperties = RetentionProperties.builder() .memoryStoreRetentionPeriodInHours(HT_TTL_HOURS) .magneticStoreRetentionPeriodInDays(CT_TTL_DAYS).build(); final UpdateTableRequest updateTableRequest = UpdateTableRequest.builder() .databaseName(DATABASE_NAME).tableName(TABLE_NAME).retentionProperties(retentionProperties).build(); timestreamWriteClient.updateTable(updateTableRequest); System.out.println("Table updated"); }
- Go
-
// Update table. magneticStoreRetentionPeriodInDays := int64(7 * 365) memoryStoreRetentionPeriodInHours := int64(24) updateTableInput := ×treamwrite.UpdateTableInput{ DatabaseName: aws.String(*databaseName), TableName: aws.String(*tableName), RetentionProperties: ×treamwrite.RetentionProperties{ MagneticStoreRetentionPeriodInDays: &magneticStoreRetentionPeriodInDays, MemoryStoreRetentionPeriodInHours: &memoryStoreRetentionPeriodInHours, }, } updateTableOutput, err := writeSvc.UpdateTable(updateTableInput) if err != nil { fmt.Println("Error:") fmt.Println(err) } else { fmt.Println("Update table is successful, below is the output:") fmt.Println(updateTableOutput) }
- Python
-
def update_table(self): print("Updating table") retention_properties = { 'MemoryStoreRetentionPeriodInHours': Constant.HT_TTL_HOURS, 'MagneticStoreRetentionPeriodInDays': Constant.CT_TTL_DAYS } try: self.client.update_table(DatabaseName=Constant.DATABASE_NAME, TableName=Constant.TABLE_NAME, RetentionProperties=retention_properties) print("Table updated.") except Exception as err: print("Update table 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 UpdateTableCommand and UpdateTable.
import { TimestreamWriteClient, UpdateTableCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" }); const params = { DatabaseName: "testDbFromNode", TableName: "testTableFromNode", RetentionProperties: { MemoryStoreRetentionPeriodInHours: 24, MagneticStoreRetentionPeriodInDays: 180 } }; const command = new UpdateTableCommand(params); try { const data = await writeClient.send(command); console.log("Table updated") } catch (error) { console.log("Error updating table. ", 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 updateTable() { console.log("Updating Table"); const params = { DatabaseName: constants.DATABASE_NAME, TableName: constants.TABLE_NAME, RetentionProperties: { MemoryStoreRetentionPeriodInHours: constants.HT_TTL_HOURS, MagneticStoreRetentionPeriodInDays: constants.CT_TTL_DAYS } }; const promise = writeClient.updateTable(params).promise(); await promise.then( (data) => { console.log("Table updated") }, (err) => { console.log("Error updating table. ", err); throw err; } ); }
- .NET
-
public async Task UpdateTable() { Console.WriteLine("Updating Table"); try { var updateTableRequest = new UpdateTableRequest { DatabaseName = Constants.DATABASE_NAME, TableName = Constants.TABLE_NAME, RetentionProperties = new RetentionProperties { MagneticStoreRetentionPeriodInDays = Constants.CT_TTL_DAYS, MemoryStoreRetentionPeriodInHours = Constants.HT_TTL_HOURS } }; UpdateTableResponse response = await writeClient.UpdateTableAsync(updateTableRequest); Console.WriteLine($"Table {Constants.TABLE_NAME} updated"); } catch (ResourceNotFoundException) { Console.WriteLine("Table does not exist."); } catch (Exception e) { Console.WriteLine("Update table failed:" + e.ToString()); } }
Describe table
Delete table