選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

DescribeTimeToLive 搭配 AWS SDK 或 CLI 使用

焦點模式
DescribeTimeToLive 搭配 AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

下列程式碼範例示範如何使用 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 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DescribeTimeToLive

Java
SDK for Java 2.x

使用 描述現有 DynamoDB 資料表上的 TTL 組態 AWS SDK for Java 2.x。

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.logging.Level; import java.util.logging.Logger; public DescribeTimeToLiveResponse describeTTL(final String tableName, final Region region) { final DescribeTimeToLiveRequest request = DescribeTimeToLiveRequest.builder().tableName(tableName).build(); try (DynamoDbClient ddb = dynamoDbClient != null ? dynamoDbClient : DynamoDbClient.builder().region(region).build()) { return ddb.describeTimeToLive(request); } catch (ResourceNotFoundException e) { System.err.format(TABLE_NOT_FOUND_ERROR, tableName); throw e; } catch (DynamoDbException e) { System.err.println(e.getMessage()); throw e; } }
  • 如需 API 詳細資訊,請參閱AWS SDK for Java 2.x 《 API 參考》中的 DescribeTimeToLive

JavaScript
適用於 JavaScript (v3) 的 SDK

使用 描述現有 DynamoDB 資料表上的 TTL 組態 AWS SDK for JavaScript。

import { DynamoDBClient, DescribeTimeToLiveCommand } from "@aws-sdk/client-dynamodb"; export const describeTTL = 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; } } // Example usage (commented out for testing) // describeTTL('your-table-name', 'us-east-1');
  • 如需 API 詳細資訊,請參閱AWS SDK for JavaScript 《 API 參考》中的 DescribeTimeToLive

Python
SDK for Python (Boto3)

使用 描述現有 DynamoDB 資料表上的 TTL 組態 AWS SDK for Python (Boto3)。

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 詳細資訊,請參閱《適用於 AWS Python (Boto3) 的 SDK API 參考》中的 DescribeTimeToLive

AWS CLI

檢視資料表的存留時間設定

下列describe-time-to-live範例顯示MusicCollection資料表的存留時間設定。

aws dynamodb describe-time-to-live \ --table-name MusicCollection

輸出:

{ "TimeToLiveDescription": { "TimeToLiveStatus": "ENABLED", "AttributeName": "ttl" } }

如需詳細資訊,請參閱《Amazon DynamoDB 開發人員指南》中的存留時間

  • 如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DescribeTimeToLive

下一個主題:

ExecuteStatement

上一個主題:

DescribeTable
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。