

D'autres exemples de AWS SDK sont disponibles dans le référentiel [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub .

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

# Utilisation `DescribeTimeToLive` avec un AWS SDK ou une CLI
<a name="dynamodb_example_dynamodb_DescribeTimeToLive_section"></a>

Les exemples de code suivants illustrent comment utiliser `DescribeTimeToLive`.

Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant : 
+  [Travaillez avec Streams et Time-to-Live](dynamodb_example_dynamodb_Scenario_StreamsAndTTL_section.md) 

------
#### [ CLI ]

**AWS CLI**  
**Pour afficher les paramètres Durée de vie (TTL) d’une table**  
L’exemple `describe-time-to-live` suivant affiche les paramètres de durée de vie de la table `MusicCollection`.  

```
aws dynamodb describe-time-to-live \
    --table-name MusicCollection
```
Sortie :  

```
{
    "TimeToLiveDescription": {
        "TimeToLiveStatus": "ENABLED",
        "AttributeName": "ttl"
    }
}
```
Pour plus d’informations, consultez [Time to Live](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html) dans le *Guide du développeur Amazon DynamoDB*.  
+  Pour plus de détails sur l'API, reportez-vous [DescribeTimeToLive](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/dynamodb/describe-time-to-live.html)à la section *Référence des AWS CLI commandes*. 

------
#### [ Java ]

**SDK pour Java 2.x**  
Décrire la configuration Durée de vie (TTL) sur une table DynamoDB existante à l’aide du kit 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;
        }
    }
```
+  Pour plus de détails sur l'API, reportez-vous [DescribeTimeToLive](https://docs.aws.amazon.com/goto/SdkForJavaV2/dynamodb-2012-08-10/DescribeTimeToLive)à la section *Référence des AWS SDK for Java 2.x API*. 

------
#### [ JavaScript ]

**SDK pour JavaScript (v3)**  
Décrivez la configuration Durée de vie (TTL) sur une table DynamoDB existante à l’aide du kit AWS SDK pour 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');
```
+  Pour plus de détails sur l'API, reportez-vous [DescribeTimeToLive](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/DescribeTimeToLiveCommand)à la section *Référence des AWS SDK pour JavaScript API*. 

------
#### [ Python ]

**Kit SDK for Python (Boto3)**  
Décrivez la configuration Durée de vie (TTL) sur une table DynamoDB existante à l’aide du kit AWS SDK pour 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")
```
+  Pour plus de détails sur l'API, consultez [DescribeTimeToLive](https://docs.aws.amazon.com/goto/boto3/dynamodb-2012-08-10/DescribeTimeToLive)le *AWS manuel de référence de l'API SDK for Python (Boto3*). 

------