本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭DescribeTimeToLive
配使用 AWS SDK或 CLI
下列程式碼範例會示範如何使用DescribeTimeToLive
。
- CLI
-
- AWS CLI
-
檢視表格的存留時間設定的步驟
下列
describe-time-to-live
範例會顯示MusicCollection
表格的「存留時間」設定。aws dynamodb describe-time-to-live \ --table-name
MusicCollection
輸出:
{ "TimeToLiveDescription": { "TimeToLiveStatus": "ENABLED", "AttributeName": "ttl" } }
如需詳細資訊,請參閱 Amazon DynamoDB 開發人員指南中的存留時間。
-
有API關詳細資訊,請參閱 DescribeTimeToLive
(AWS CLI 指令參考。
-
- Java
-
- SDK對於爪哇 2.x
-
描述現有 DynamoDB 表格上的TTL組態。
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.model.DescribeTimeToLiveRequest; import software.amazon.awssdk.services.dynamodb.model.DescribeTimeToLiveResponse; import software.amazon.awssdk.services.dynamodb.model.DynamoDbException; import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException; import java.util.Optional; final DescribeTimeToLiveRequest request = DescribeTimeToLiveRequest.builder() .tableName(tableName) .build(); try (DynamoDbClient ddb = DynamoDbClient.builder() .region(region) .build()) { final DescribeTimeToLiveResponse response = ddb.describeTimeToLive(request); System.out.println(tableName + " description of time to live is " + response.toString()); } catch (ResourceNotFoundException e) { System.err.format("Error: The Amazon DynamoDB table \"%s\" can't be found.\n", tableName); System.exit(1); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.exit(0);
-
有API關詳細資訊,請參閱 DescribeTimeToLive(AWS SDK for Java 2.x API參考。
-
- JavaScript
-
- SDK對於 JavaScript (3)
-
import { DynamoDBClient, DescribeTimeToLiveCommand } from "@aws-sdk/client-dynamodb"; const describeTableTTL = async (tableName, region) => { const client = new DynamoDBClient({ region: region, endpoint: `https://dynamodb.${region}.amazonaws.com` }); try { const ttlDescription = await client.send(new DescribeTimeToLiveCommand({ TableName: tableName })); if (ttlDescription.TimeToLiveDescription.TimeToLiveStatus === 'ENABLED') { console.log("TTL is enabled for table %s.", tableName); } else { console.log("TTL is not enabled for table %s.", tableName); } return ttlDescription; } catch (e) { console.error(`Error describing table: ${e}`); throw e; } } // enter table name and change region if desired. describeTableTTL('your-table-name', 'us-east-1');
-
有API關詳細資訊,請參閱 DescribeTimeToLive(AWS SDK for JavaScript API參考。
-
- Python
-
- SDK對於 Python(肉毒桿菌 3)
-
import boto3 def describe_ttl(table_name, region): """ Describes TTL on an existing table, as well as a region. :param table_name: String representing the name of the table :param region: AWS Region of the table - example `us-east-1` :return: Time to live description. """ try: dynamodb = boto3.resource('dynamodb', region_name=region) ttl_description = dynamodb.describe_time_to_live(TableName=table_name) print( f"TimeToLive for table {table_name} is status {ttl_description['TimeToLiveDescription']['TimeToLiveStatus']}") return ttl_description except Exception as e: print(f"Error describing table: {e}") raise # Enter your own table name and AWS region describe_ttl('your-table-name', 'us-east-1')
-
有API關詳細資訊,請參閱 DescribeTimeToLive(AWS SDK對於 Python(肉毒桿 3)API參考。
-
有關的完整列表 AWS SDK開發人員指南和代碼示例,請參閱搭配使 DynamoDB AWS SDK。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。
DescribeTable
ExecuteStatement