Exemples DynamoDB utilisant AWS CLI - AWS Command Line Interface

Cette documentation concerne AWS CLI uniquement la version 1. Pour la documentation relative à la version 2 du AWS CLI, consultez le guide de l'utilisateur de la version 2.

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.

Exemples DynamoDB utilisant AWS CLI

Les exemples de code suivants vous montrent comment effectuer des actions et implémenter des scénarios courants à l' AWS Command Line Interface aide de DynamoDB.

Les actions sont des extraits de code de programmes plus larges et doivent être exécutées dans leur contexte. Alors que les actions vous indiquent comment appeler des fonctions de service individuelles, vous pouvez les voir en contexte dans leurs scénarios associés.

Chaque exemple inclut un lien vers le code source complet, où vous trouverez des instructions sur la configuration et l’exécution du code en contexte.

Rubriques

Actions

L'exemple de code suivant montre comment utiliserbatch-get-item.

AWS CLI

Pour extraire plusieurs éléments d’une table

L’exemple batch-get-items suivant lit plusieurs éléments de la table MusicCollection à l’aide d’un lot de trois demandes GetItem, et demande le nombre d’unités de capacité de lecture consommées par l’opération. La commande renvoie uniquement l’attribut AlbumTitle.

aws dynamodb batch-get-item \ --request-items file://request-items.json \ --return-consumed-capacity TOTAL

Contenu de request-items.json :

{ "MusicCollection": { "Keys": [ { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"} }, { "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }, { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Scared of My Shadow"} } ], "ProjectionExpression":"AlbumTitle" } }

Sortie :

{ "Responses": { "MusicCollection": [ { "AlbumTitle": { "S": "Somewhat Famous" } }, { "AlbumTitle": { "S": "Blue Sky Blues" } }, { "AlbumTitle": { "S": "Louder Than Ever" } } ] }, "UnprocessedKeys": {}, "ConsumedCapacity": [ { "TableName": "MusicCollection", "CapacityUnits": 1.5 } ] }

Pour plus d’informations, consultez Opérations par lots dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous BatchGetItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserbatch-write-item.

AWS CLI

Pour ajouter plusieurs éléments à une table

L’exemple batch-write-item suivant ajoute trois nouveaux éléments à la table MusicCollection à l’aide d’un lot de trois demandes PutItem. Il demande également des informations sur le nombre d’unités de capacité d’écriture consommées par l’opération et sur les collections d’éléments modifiées par l’opération.

aws dynamodb batch-write-item \ --request-items file://request-items.json \ --return-consumed-capacity INDEXES \ --return-item-collection-metrics SIZE

Contenu de request-items.json :

{ "MusicCollection": [ { "PutRequest": { "Item": { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"} } } }, { "PutRequest": { "Item": { "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"}, "AlbumTitle": {"S": "Songs About Life"} } } }, { "PutRequest": { "Item": { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Scared of My Shadow"}, "AlbumTitle": {"S": "Blue Sky Blues"} } } } ] }

Sortie :

{ "UnprocessedItems": {}, "ItemCollectionMetrics": { "MusicCollection": [ { "ItemCollectionKey": { "Artist": { "S": "No One You Know" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] }, { "ItemCollectionKey": { "Artist": { "S": "Acme Band" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] } ] }, "ConsumedCapacity": [ { "TableName": "MusicCollection", "CapacityUnits": 6.0, "Table": { "CapacityUnits": 3.0 }, "LocalSecondaryIndexes": { "AlbumTitleIndex": { "CapacityUnits": 3.0 } } } ] }

Pour plus d’informations, consultez Opérations par lots dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous BatchWriteItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utilisercreate-backup.

AWS CLI

Pour créer une sauvegarde pour une table existante DynamoDB

L’exemple create-backup suivant crée une sauvegarde à partir de la table MusicCollection.

aws dynamodb create-backup \ --table-name MusicCollection \ --backup-name MusicCollectionBackup

Sortie :

{ "BackupDetails": { "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a", "BackupName": "MusicCollectionBackup", "BackupSizeBytes": 0, "BackupStatus": "CREATING", "BackupType": "USER", "BackupCreationDateTime": 1576616366.715 } }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous CreateBackupà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utilisercreate-global-table.

AWS CLI

Pour créer une table globale

L'create-global-tableexemple suivant crée une table globale à partir de deux tables identiques dans les AWS régions distinctes spécifiées.

aws dynamodb create-global-table \ --global-table-name MusicCollection \ --replication-group RegionName=us-east-2 RegionName=us-east-1 \ --region us-east-2

Sortie :

{ "GlobalTableDescription": { "ReplicationGroup": [ { "RegionName": "us-east-2" }, { "RegionName": "us-east-1" } ], "GlobalTableArn": "arn:aws:dynamodb::123456789012:global-table/MusicCollection", "CreationDateTime": 1576625818.532, "GlobalTableStatus": "CREATING", "GlobalTableName": "MusicCollection" } }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous CreateGlobalTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utilisercreate-table.

AWS CLI

Exemple 1 : pour créer une table avec des balises

L’exemple create-table suivant utilise les attributs et le schéma de clés spécifiés pour créer une table nommée MusicCollection. Cette table utilise le débit provisionné et est chiffrée au repos à l'aide de la clé CMK AWS détenue par défaut. La commande applique également une balise à la table, avec une clé Owner et une valeur blueTeam.

aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \ --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \ --tags Key=Owner,Value=blueTeam

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 }, "TableSizeBytes": 0, "TableName": "MusicCollection", "TableStatus": "CREATING", "KeySchema": [ { "KeyType": "HASH", "AttributeName": "Artist" }, { "KeyType": "RANGE", "AttributeName": "SongTitle" } ], "ItemCount": 0, "CreationDateTime": "2020-05-26T16:04:41.627000-07:00", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour créer une table en mode à la demande

L’exemple suivant crée une table appelée MusicCollection en mode à la demande, plutôt qu’en mode débit provisionné. Cela est utile pour les tables dont les charges de travail sont imprévisibles.

aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \ --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-05-27T11:44:10.807000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 0, "WriteCapacityUnits": 0 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" } } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour créer une table et la chiffrer à l’aide d’une clé CMK gérée par le client

L’exemple suivant crée une table nommée MusicCollection et la chiffre à l’aide d’une clé CMK gérée par le client.

aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \ --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \ --sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=abcd1234-abcd-1234-a123-ab1234a1b234

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-05-27T11:12:16.431000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "SSEDescription": { "Status": "ENABLED", "SSEType": "KMS", "KMSMasterKeyArn": "arn:aws:kms:us-west-2:123456789012:key/abcd1234-abcd-1234-a123-ab1234a1b234" } } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 4 : pour créer une table avec un index secondaire local

L’exemple suivant utilise les attributs et le schéma de clés spécifiés pour créer une table nommée MusicCollection avec un index local secondaire nommé AlbumTitleIndex.

aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S AttributeName=AlbumTitle,AttributeType=S \ --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --local-secondary-indexes \ "[ { \"IndexName\": \"AlbumTitleIndex\", \"KeySchema\": [ {\"AttributeName\": \"Artist\",\"KeyType\":\"HASH\"}, {\"AttributeName\": \"AlbumTitle\",\"KeyType\":\"RANGE\"} ], \"Projection\": { \"ProjectionType\": \"INCLUDE\", \"NonKeyAttributes\": [\"Genre\", \"Year\"] } } ]"

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-05-26T15:59:49.473000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "LocalSecondaryIndexes": [ { "IndexName": "AlbumTitleIndex", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "AlbumTitle", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "Genre", "Year" ] }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitleIndex" } ] } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 5 : pour créer une table avec un index secondaire global

L’exemple suivant crée une table nommée GameScores avec un index secondaire global nommé GameTitleIndex. La table de base a une clé de partition UserId et une clé de tri GameTitle, vous permettant de trouver efficacement le meilleur score d’un utilisateur pour un jeu spécifique, tandis que l’index secondaire global (GSI) a une clé de partition GameTitle et une clé de tri TopScore, vous permettant de trouver rapidement le score le plus élevé pour un jeu particulier.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S AttributeName=TopScore,AttributeType=N \ --key-schema AttributeName=UserId,KeyType=HASH \ AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --global-secondary-indexes \ "[ { \"IndexName\": \"GameTitleIndex\", \"KeySchema\": [ {\"AttributeName\":\"GameTitle\",\"KeyType\":\"HASH\"}, {\"AttributeName\":\"TopScore\",\"KeyType\":\"RANGE\"} ], \"Projection\": { \"ProjectionType\":\"INCLUDE\", \"NonKeyAttributes\":[\"UserId\"] }, \"ProvisionedThroughput\": { \"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5 } } ]"

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "TopScore", "AttributeType": "N" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-05-26T17:28:15.602000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "GlobalSecondaryIndexes": [ { "IndexName": "GameTitleIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "TopScore", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "UserId" ] }, "IndexStatus": "CREATING", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores/index/GameTitleIndex" } ] } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 6 : pour créer une table avec plusieurs index secondaires globaux à la fois

L’exemple suivant crée une table nommée GameScores avec deux index secondaires globaux. Les schémas GSI sont transmis via un fichier plutôt que sur la ligne de commande.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S AttributeName=TopScore,AttributeType=N AttributeName=Date,AttributeType=S \ --key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --global-secondary-indexes file://gsi.json

Contenu de gsi.json :

[ { "IndexName": "GameTitleIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "TopScore", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 } }, { "IndexName": "GameDateIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "Date", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "ALL" }, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 } } ]

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Date", "AttributeType": "S" }, { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "TopScore", "AttributeType": "N" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-08-04T16:40:55.524000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "GlobalSecondaryIndexes": [ { "IndexName": "GameTitleIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "TopScore", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "ALL" }, "IndexStatus": "CREATING", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores/index/GameTitleIndex" }, { "IndexName": "GameDateIndex", "KeySchema": [ { "AttributeName": "GameTitle", "KeyType": "HASH" }, { "AttributeName": "Date", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "ALL" }, "IndexStatus": "CREATING", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores/index/GameDateIndex" } ] } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 7 : pour créer une table avec Streams activé

L’exemple suivant crée une table appelée GameScores avec DynamoDB Streams activé. Les nouvelles et les anciennes images de chaque élément seront écrites dans le flux.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S \ --key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --stream-specification StreamEnabled=TRUE,StreamViewType=NEW_AND_OLD_IMAGES

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2020-05-27T10:49:34.056000-07:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "StreamSpecification": { "StreamEnabled": true, "StreamViewType": "NEW_AND_OLD_IMAGES" }, "LatestStreamLabel": "2020-05-27T17:49:34.056", "LatestStreamArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores/stream/2020-05-27T17:49:34.056" } }

Pour plus d’informations, consultez Opérations de base pour les tables dans le Guide du développeur Amazon DynamoDB.

Exemple 8 : pour créer une table avec Keys-Only Stream activé

L’exemple suivant crée une table appelée GameScores avec DynamoDB Streams activé. Seuls les attributs clés des éléments modifiés sont écrits dans le flux.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S \ --key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --stream-specification StreamEnabled=TRUE,StreamViewType=KEYS_ONLY

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2023-05-25T18:45:34.140000+00:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "StreamSpecification": { "StreamEnabled": true, "StreamViewType": "KEYS_ONLY" }, "LatestStreamLabel": "2023-05-25T18:45:34.140", "LatestStreamArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores/stream/2023-05-25T18:45:34.140", "DeletionProtectionEnabled": false } }

Pour plus d’informations, consultez Modifier la récupération de données pour DynamoDB Streams dans le Guide du développeur Amazon DynamoDB.

Exemple 9 : pour créer une table à l’aide de la classe Standard Infrequent Access

L’exemple suivant crée une table appelée GameScores et attribue la classe de table Standard-Infrequent Access (DynamoDB Standard-IA). Cette classe de table est optimisée pour le stockage, qui constitue le principal coût.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S \ --key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --table-class STANDARD_INFREQUENT_ACCESS

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2023-05-25T18:33:07.581000+00:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableClassSummary": { "TableClass": "STANDARD_INFREQUENT_ACCESS" }, "DeletionProtectionEnabled": false } }

Pour plus d’informations, consultez Classes de tables dans le Guide du développeur Amazon DynamoDB.

Exemple 10 : pour créer une table avec la protection contre la suppression activée

L’exemple suivant crée une table appelée GameScores et active la protection contre la suppression.

aws dynamodb create-table \ --table-name GameScores \ --attribute-definitions AttributeName=UserId,AttributeType=S AttributeName=GameTitle,AttributeType=S \ --key-schema AttributeName=UserId,KeyType=HASH AttributeName=GameTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 \ --deletion-protection-enabled

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "GameTitle", "AttributeType": "S" }, { "AttributeName": "UserId", "AttributeType": "S" } ], "TableName": "GameScores", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "GameTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2023-05-25T23:02:17.093000+00:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/GameScores", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "DeletionProtectionEnabled": true } }

Pour plus d’informations, consultez Utilisation de la protection contre la suppression dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous CreateTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdelete-backup.

AWS CLI

Pour supprimer une sauvegarde DynamoDB existante

L’exemple delete-backup suivant supprime la sauvegarde existante spécifiée.

aws dynamodb delete-backup \ --backup-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a

Sortie :

{ "BackupDescription": { "BackupDetails": { "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a", "BackupName": "MusicCollectionBackup", "BackupSizeBytes": 0, "BackupStatus": "DELETED", "BackupType": "USER", "BackupCreationDateTime": 1576616366.715 }, "SourceTableDetails": { "TableName": "MusicCollection", "TableId": "b0c04bcc-309b-4352-b2ae-9088af169fe2", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableSizeBytes": 0, "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableCreationDateTime": 1576615228.571, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "ItemCount": 0, "BillingMode": "PROVISIONED" }, "SourceTableFeatureDetails": {} } }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DeleteBackupà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdelete-item.

AWS CLI

Exemple 1 : pour supprimer un élément

L’exemple delete-item suivant supprime un élément de la table MusicCollection et demande des informations sur l’élément supprimé et sur la capacité utilisée par la demande.

aws dynamodb delete-item \ --table-name MusicCollection \ --key file://key.json \ --return-values ALL_OLD \ --return-consumed-capacity TOTAL \ --return-item-collection-metrics SIZE

Contenu de key.json :

{ "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Scared of My Shadow"} }

Sortie :

{ "Attributes": { "AlbumTitle": { "S": "Blue Sky Blues" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Scared of My Shadow" } }, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 2.0 }, "ItemCollectionMetrics": { "ItemCollectionKey": { "Artist": { "S": "No One You Know" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] } }

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour supprimer un élément sous certaines conditions

L’exemple suivant supprime un élément de la table ProductCatalog uniquement si ProductCategory est Sporting Goods ou Gardening Supplies et si son prix est compris entre 500 et 600. Elle renvoie des informations sur l’élément qui a été supprimé.

aws dynamodb delete-item \ --table-name ProductCatalog \ --key '{"Id":{"N":"456"}}' \ --condition-expression "(ProductCategory IN (:cat1, :cat2)) and (#P between :lo and :hi)" \ --expression-attribute-names file://names.json \ --expression-attribute-values file://values.json \ --return-values ALL_OLD

Contenu de names.json :

{ "#P": "Price" }

Contenu de values.json :

{ ":cat1": {"S": "Sporting Goods"}, ":cat2": {"S": "Gardening Supplies"}, ":lo": {"N": "500"}, ":hi": {"N": "600"} }

Sortie :

{ "Attributes": { "Id": { "N": "456" }, "Price": { "N": "550" }, "ProductCategory": { "S": "Sporting Goods" } } }

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DeleteItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdelete-table.

AWS CLI

Pour supprimer une table

L’exemple delete-table suivant supprime la table MusicCollection.

aws dynamodb delete-table \ --table-name MusicCollection

Sortie :

{ "TableDescription": { "TableStatus": "DELETING", "TableSizeBytes": 0, "ItemCount": 0, "TableName": "MusicCollection", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 } } }

Pour plus d’informations, consultez Suppression d’une table dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DeleteTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-backup.

AWS CLI

Pour obtenir des informations sur une sauvegarde existante d’une table

L’exemple describe-backup suivant affiche des informations sur la sauvegarde existante spécifiée.

aws dynamodb describe-backup \ --backup-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a

Sortie :

{ "BackupDescription": { "BackupDetails": { "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a", "BackupName": "MusicCollectionBackup", "BackupSizeBytes": 0, "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupCreationDateTime": 1576616366.715 }, "SourceTableDetails": { "TableName": "MusicCollection", "TableId": "b0c04bcc-309b-4352-b2ae-9088af169fe2", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableSizeBytes": 0, "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableCreationDateTime": 1576615228.571, "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "ItemCount": 0, "BillingMode": "PROVISIONED" }, "SourceTableFeatureDetails": {} } }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DescribeBackupà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-continuous-backups.

AWS CLI

Pour obtenir des informations sur les sauvegardes continues d’une table DynamoDB

L’exemple describe-continuous-backups suivant affiche des détails sur les paramètres de sauvegarde continue de la table MusicCollection.

aws dynamodb describe-continuous-backups \ --table-name MusicCollection

Sortie :

{ "ContinuousBackupsDescription": { "ContinuousBackupsStatus": "ENABLED", "PointInTimeRecoveryDescription": { "PointInTimeRecoveryStatus": "DISABLED" } } }

Pour plus d'informations, consultez la section Point-in-Time Recovery for DynamoDB dans le manuel du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserdescribe-contributor-insights.

AWS CLI

Pour afficher les paramètres Contributor Insights d’une table DynamoDB

L’exemple describe-contributor-insights suivant affiche les paramètres de Contributor Insights pour la table MusicCollection et l’index secondaire global AlbumTitle-index.

aws dynamodb describe-contributor-insights \ --table-name MusicCollection \ --index-name AlbumTitle-index

Sortie :

{ "TableName": "MusicCollection", "IndexName": "AlbumTitle-index", "ContributorInsightsRuleList": [ "DynamoDBContributorInsights-PKC-MusicCollection-1576629651520", "DynamoDBContributorInsights-SKC-MusicCollection-1576629651520", "DynamoDBContributorInsights-PKT-MusicCollection-1576629651520", "DynamoDBContributorInsights-SKT-MusicCollection-1576629651520" ], "ContributorInsightsStatus": "ENABLED", "LastUpdateDateTime": 1576629654.78 }

Pour plus d'informations, consultez la section Analyse de l'accès aux données à l'aide de CloudWatch Contributor Insights for DynamoDB dans le manuel du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserdescribe-endpoints.

AWS CLI

Pour afficher des informations sur les points de terminaison régionaux

L'describe-endpointsexemple suivant affiche des détails sur les points de terminaison de la AWS région actuelle.

aws dynamodb describe-endpoints

Sortie :

{ "Endpoints": [ { "Address": "dynamodb.us-west-2.amazonaws.com", "CachePeriodInMinutes": 1440 } ] }

Pour plus d’informations, consultez Points de terminaison et quotas Amazon DynamoDB dans les Références générales AWS .

  • Pour plus de détails sur l'API, reportez-vous DescribeEndpointsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-global-table-settings.

AWS CLI

Pour obtenir des informations sur les paramètres d’une table globale DynamoDB

L’exemple describe-global-table-settings suivant affiche les paramètres de la table globale MusicCollection.

aws dynamodb describe-global-table-settings \ --global-table-name MusicCollection

Sortie :

{ "GlobalTableName": "MusicCollection", "ReplicaSettings": [ { "RegionName": "us-east-1", "ReplicaStatus": "ACTIVE", "ReplicaProvisionedReadCapacityUnits": 10, "ReplicaProvisionedReadCapacityAutoScalingSettings": { "AutoScalingDisabled": true }, "ReplicaProvisionedWriteCapacityUnits": 5, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "AutoScalingDisabled": true } }, { "RegionName": "us-east-2", "ReplicaStatus": "ACTIVE", "ReplicaProvisionedReadCapacityUnits": 10, "ReplicaProvisionedReadCapacityAutoScalingSettings": { "AutoScalingDisabled": true }, "ReplicaProvisionedWriteCapacityUnits": 5, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "AutoScalingDisabled": true } } ] }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserdescribe-global-table.

AWS CLI

Pour afficher des informations sur une table globale DynamoDB

L’exemple describe-global-table suivant affiche des informations sur la table globale MusicCollection.

aws dynamodb describe-global-table \ --global-table-name MusicCollection

Sortie :

{ "GlobalTableDescription": { "ReplicationGroup": [ { "RegionName": "us-east-2" }, { "RegionName": "us-east-1" } ], "GlobalTableArn": "arn:aws:dynamodb::123456789012:global-table/MusicCollection", "CreationDateTime": 1576625818.532, "GlobalTableStatus": "ACTIVE", "GlobalTableName": "MusicCollection" } }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DescribeGlobalTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-limits.

AWS CLI

Pour afficher les limites de capacité allouée

L'describe-limitsexemple suivant affiche les limites de capacité allouées pour votre compte dans la région actuelle. AWS

aws dynamodb describe-limits

Sortie :

{ "AccountMaxReadCapacityUnits": 80000, "AccountMaxWriteCapacityUnits": 80000, "TableMaxReadCapacityUnits": 40000, "TableMaxWriteCapacityUnits": 40000 }

Pour plus d’informations, consultez Limites dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DescribeLimitsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-table-replica-auto-scaling.

AWS CLI

Pour afficher les paramètres autoscaling sur les réplicas d’une table globale

L’exemple describe-table-replica-auto-scaling suivant affiche les paramètres autoscaling entre les réplicas de la table globale MusicCollection.

aws dynamodb describe-table-replica-auto-scaling \ --table-name MusicCollection

Sortie :

{ "TableAutoScalingDescription": { "TableName": "MusicCollection", "TableStatus": "ACTIVE", "Replicas": [ { "RegionName": "us-east-1", "GlobalSecondaryIndexes": [], "ReplicaProvisionedReadCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBReadCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaStatus": "ACTIVE" }, { "RegionName": "us-east-2", "GlobalSecondaryIndexes": [], "ReplicaProvisionedReadCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBReadCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaStatus": "ACTIVE" } ] } }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserdescribe-table.

AWS CLI

Pour décrire un tableau

L’exemple describe-table suivant décrit la table MusicCollection.

aws dynamodb describe-table \ --table-name MusicCollection

Sortie :

{ "Table": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 }, "TableSizeBytes": 0, "TableName": "MusicCollection", "TableStatus": "ACTIVE", "KeySchema": [ { "KeyType": "HASH", "AttributeName": "Artist" }, { "KeyType": "RANGE", "AttributeName": "SongTitle" } ], "ItemCount": 0, "CreationDateTime": 1421866952.062 } }

Pour plus d’informations, consultez Description d’une table dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DescribeTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserdescribe-time-to-live.

AWS CLI

Pour afficher les paramètres de 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 dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous DescribeTimeToLiveà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserget-item.

AWS CLI

Exemple 1 : pour lire un élément dans une table

L’exemple get-item suivant récupère un élément de la table MusicCollection. La table possède une clé hash-and-range primaire (ArtistetSongTitle), vous devez donc spécifier ces deux attributs. La commande demande également des informations sur la capacité de lecture consommée par l’opération.

aws dynamodb get-item \ --table-name MusicCollection \ --key file://key.json \ --return-consumed-capacity TOTAL

Contenu de key.json :

{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }

Sortie :

{ "Item": { "AlbumTitle": { "S": "Songs About Life" }, "SongTitle": { "S": "Happy Day" }, "Artist": { "S": "Acme Band" } }, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 0.5 } }

Pour plus d’informations, consultez Lecture d’un élément dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour lire un élément en utilisant une lecture cohérente

L’exemple suivant récupère un élément à partir de la table MusicCollection à l’aide de la lecture fortement cohérente.

aws dynamodb get-item \ --table-name MusicCollection \ --key file://key.json \ --consistent-read \ --return-consumed-capacity TOTAL

Contenu de key.json :

{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }

Sortie :

{ "Item": { "AlbumTitle": { "S": "Songs About Life" }, "SongTitle": { "S": "Happy Day" }, "Artist": { "S": "Acme Band" } }, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 1.0 } }

Pour plus d’informations, consultez Lecture d’un élément dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour extraire des attributs spécifiques d’un élément

L’exemple suivant utilise une expression de projection pour extraire uniquement trois attributs de l’élément souhaité.

aws dynamodb get-item \ --table-name ProductCatalog \ --key '{"Id": {"N": "102"}}' \ --projection-expression "#T, #C, #P" \ --expression-attribute-names file://names.json

Contenu de names.json :

{ "#T": "Title", "#C": "ProductCategory", "#P": "Price" }

Sortie :

{ "Item": { "Price": { "N": "20" }, "Title": { "S": "Book 102 Title" }, "ProductCategory": { "S": "Book" } } }

Pour plus d’informations, consultez Lecture d’un élément dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous GetItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserlist-backups.

AWS CLI

Exemple 1 : pour répertorier toutes les sauvegardes DynamoDB existantes

L’exemple list-backups suivant répertorie toutes vos sauvegardes existantes.

aws dynamodb list-backups

Sortie :

{ "BackupSummaries": [ { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 }, { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-b2abc345", "BackupName": "MusicCollectionBackup2", "BackupCreationDateTime": "2020-06-26T11:08:35.431000-07:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 400 } ] }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour répertorier les sauvegardes créées par l’utilisateur dans un intervalle de temps spécifique

L’exemple suivant répertorie uniquement les sauvegardes de la table MusicCollection créées par l’utilisateur (et non celles créées automatiquement par DynamoDB) dont la date de création est comprise entre le 1er janvier 2020 et le 1er mars 2020.

aws dynamodb list-backups \ --table-name MusicCollection \ --time-range-lower-bound 1577836800 \ --time-range-upper-bound 1583020800 \ --backup-type USER

Sortie :

{ "BackupSummaries": [ { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 } ] }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour limiter la taille de page

L’exemple suivant renvoie une liste de toutes les sauvegardes existantes, mais récupère un seul élément par appel, en effectuant plusieurs appels si nécessaire pour obtenir la liste complète. La limitation de la taille de page est utile lorsque vous exécutez des commandes de liste sur un grand nombre de ressources, ce qui peut entraîner une erreur d’expiration de délai lorsque la taille de page par défaut utilisée est de 1 000.

aws dynamodb list-backups \ --page-size 1

Sortie :

{ "BackupSummaries": [ { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 }, { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-b2abc345", "BackupName": "MusicCollectionBackup2", "BackupCreationDateTime": "2020-06-26T11:08:35.431000-07:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 400 } ] }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 4 : pour limiter le nombre d’éléments retournés

L’exemple suivant limite le nombre d’éléments retournés à 1. La réponse inclut une valeur NextToken permettant d’extraire la page suivante des résultats.

aws dynamodb list-backups \ --max-items 1

Sortie :

{ "BackupSummaries": [ { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 } ], "NextToken": "abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9" }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 5 : pour extraire la page de résultats suivante

La commande suivante utilise la valeur NextToken d’un appel précédent à la commande list-backups pour extraire une autre page de résultats. Dans ce cas, comme la réponse n’inclut aucune valeur NextToken, nous savons que nous avons atteint la fin des résultats.

aws dynamodb list-backups \ --starting-token abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9

Output

{ "BackupSummaries": [ { "TableName": "MusicCollection", "TableId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "BackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01234567890123-b2abc345", "BackupName": "MusicCollectionBackup2", "BackupCreationDateTime": "2020-06-26T11:08:35.431000-07:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 400 } ] }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous ListBackupsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserlist-contributor-insights.

AWS CLI

Exemple 1 : pour afficher une liste de récapitulatifs de Contributor Insights

L’exemple list-contributor-insights suivant affiche une liste de récapitulatifs de Contributor Insights.

aws dynamodb list-contributor-insights

Sortie :

{ "ContributorInsightsSummaries": [ { "TableName": "MusicCollection", "IndexName": "AlbumTitle-index", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "ProductCatalog", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "Forum", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "Reply", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "Thread", "ContributorInsightsStatus": "ENABLED" } ] }

Pour plus d'informations, consultez la section Analyse de l'accès aux données à l'aide de CloudWatch Contributor Insights for DynamoDB dans le manuel du développeur Amazon DynamoDB.

Exemple 2 : pour limiter le nombre d’éléments retournés

L’exemple suivant limite le nombre d’éléments renvoyés à 4. La réponse inclut une valeur NextToken permettant d’extraire la page suivante des résultats.

aws dynamodb list-contributor-insights \ --max-results 4

Sortie :

{ "ContributorInsightsSummaries": [ { "TableName": "MusicCollection", "IndexName": "AlbumTitle-index", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "ProductCatalog", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "Forum", "ContributorInsightsStatus": "ENABLED" } ], "NextToken": "abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9" }

Pour plus d'informations, consultez la section Analyse de l'accès aux données à l'aide de CloudWatch Contributor Insights for DynamoDB dans le manuel du développeur Amazon DynamoDB.

Exemple 3 : pour extraire la page de résultats suivante

La commande suivante utilise la valeur NextToken d’un appel précédent à la commande list-contributor-insights pour extraire une autre page de résultats. Dans ce cas, comme la réponse n’inclut aucune valeur NextToken, nous savons que nous avons atteint la fin des résultats.

aws dynamodb list-contributor-insights \ --max-results 4 \ --next-token abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9

Sortie :

{ "ContributorInsightsSummaries": [ { "TableName": "Reply", "ContributorInsightsStatus": "ENABLED" }, { "TableName": "Thread", "ContributorInsightsStatus": "ENABLED" } ] }

Pour plus d'informations, consultez la section Analyse de l'accès aux données à l'aide de CloudWatch Contributor Insights for DynamoDB dans le manuel du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous ListContributorInsightsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserlist-global-tables.

AWS CLI

Pour répertorier les tables globales DynamoDB existantes

L’exemple list-global-tables suivant répertorie toutes vos tables globales existantes.

aws dynamodb list-global-tables

Sortie :

{ "GlobalTables": [ { "GlobalTableName": "MusicCollection", "ReplicationGroup": [ { "RegionName": "us-east-2" }, { "RegionName": "us-east-1" } ] } ] }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous ListGlobalTablesà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserlist-tables.

AWS CLI

Exemple 1 : pour répertorier les tables

L'list-tablesexemple suivant répertorie toutes les tables associées au AWS compte courant et à la région.

aws dynamodb list-tables

Sortie :

{ "TableNames": [ "Forum", "ProductCatalog", "Reply", "Thread" ] }

Pour plus d’informations, consultez Liste des noms de tables dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour limiter la taille de page

L’exemple suivant renvoie une liste de toutes les tables existantes, mais extrait un seul élément par appel, en effectuant plusieurs appels si nécessaire pour obtenir la liste complète. La limitation de la taille de page est utile lorsque vous exécutez des commandes de liste sur un grand nombre de ressources, ce qui peut entraîner une erreur « expiré » lors de l’utilisation du format de page par défaut de 1 000.

aws dynamodb list-tables \ --page-size 1

Sortie :

{ "TableNames": [ "Forum", "ProductCatalog", "Reply", "Thread" ] }

Pour plus d’informations, consultez Liste des noms de tables dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour limiter le nombre d’éléments retournés

L’exemple suivant limite le nombre d’éléments renvoyés à 2. La réponse inclut une valeur NextToken permettant d’extraire la page suivante des résultats.

aws dynamodb list-tables \ --max-items 2

Sortie :

{ "TableNames": [ "Forum", "ProductCatalog" ], "NextToken": "abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9" }

Pour plus d’informations, consultez Liste des noms de tables dans le Guide du développeur Amazon DynamoDB.

Exemple 4 : pour récupérer la page de résultats suivante

La commande suivante utilise la valeur NextToken d’un appel précédent à la commande list-tables pour récupérer une autre page de résultats. Dans ce cas, comme la réponse n’inclut aucune valeur NextToken, nous savons que nous avons atteint la fin des résultats.

aws dynamodb list-tables \ --starting-token abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9

Sortie :

{ "TableNames": [ "Reply", "Thread" ] }

Pour plus d’informations, consultez Liste des noms de tables dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous ListTablesà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserlist-tags-of-resource.

AWS CLI

Exemple 1 : pour répertorier les balises d’une ressource DynamoDB

L’exemple list-tags-of-resource suivant affiche les balises de la table MusicCollection.

aws dynamodb list-tags-of-resource \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection

Sortie :

{ "Tags": [ { "Key": "Owner", "Value": "blueTeam" }, { "Key": "Environment", "Value": "Production" } ] }

Pour plus d’informations, consultez Balisage pour DynamoDBdans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour limiter le nombre de balises retournées

L’exemple suivant limite le nombre de balises retournées à 1. La réponse inclut une valeur NextToken permettant d’extraire la page suivante des résultats.

aws dynamodb list-tags-of-resource \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --max-items 1

Sortie :

{ "Tags": [ { "Key": "Owner", "Value": "blueTeam" } ], "NextToken": "abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9" }

Pour plus d’informations, consultez Balisage pour DynamoDBdans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour extraire la page de résultats suivante

La commande suivante utilise la valeur NextToken d’un appel précédent à la commande list-tags-of-resource pour extraire une autre page de résultats. Dans ce cas, comme la réponse n’inclut aucune valeur NextToken, nous savons que nous avons atteint la fin des résultats.

aws dynamodb list-tags-of-resource \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --starting-token abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9

Sortie :

{ "Tags": [ { "Key": "Environment", "Value": "Production" } ] }

Pour plus d’informations, consultez Balisage pour DynamoDBdans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous ListTagsOfResourceà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserput-item.

AWS CLI

Exemple 1 : pour ajouter un élément à une table

L'put-itemexemple suivant ajoute un nouvel élément au MusicCollectiontableau.

aws dynamodb put-item \ --table-name MusicCollection \ --item file://item.json \ --return-consumed-capacity TOTAL \ --return-item-collection-metrics SIZE

Contenu de item.json :

{ "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Greatest Hits"} }

Sortie :

{ "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 1.0 }, "ItemCollectionMetrics": { "ItemCollectionKey": { "Artist": { "S": "No One You Know" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] } }

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour remplacer un élément d’une table sous certaines conditions

L’exemple put-item suivant remplace un élément existant dans la table MusicCollection uniquement si celui-ci possède un attribut AlbumTitle dont la valeur est Greatest Hits. La commande renvoie la valeur précédente de l’élément.

aws dynamodb put-item \ --table-name MusicCollection \ --item file://item.json \ --condition-expression "#A = :A" \ --expression-attribute-names file://names.json \ --expression-attribute-values file://values.json \ --return-values ALL_OLD

Contenu de item.json :

{ "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"} }

Contenu de names.json :

{ "#A": "AlbumTitle" }

Contenu de values.json :

{ ":A": {"S": "Greatest Hits"} }

Sortie :

{ "Attributes": { "AlbumTitle": { "S": "Greatest Hits" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Call Me Today" } } }

Si la clé existe déjà, vous devriez voir la sortie suivante :

A client error (ConditionalCheckFailedException) occurred when calling the PutItem operation: The conditional request failed.

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous PutItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserquery.

AWS CLI

Exemple 1 : pour interroger une table

L’exemple query suivant interroge des éléments dans la table MusicCollection. La table possède une clé hash-and-range primaire (ArtistetSongTitle), mais cette requête indique uniquement la valeur de la clé de hachage. Elle renvoie les titres des chansons de l’artiste « No One You Know ».

aws dynamodb query \ --table-name MusicCollection \ --projection-expression "SongTitle" \ --key-condition-expression "Artist = :v1" \ --expression-attribute-values file://expression-attributes.json \ --return-consumed-capacity TOTAL

Contenu de expression-attributes.json :

{ ":v1": {"S": "No One You Know"} }

Sortie :

{ "Items": [ { "SongTitle": { "S": "Call Me Today" }, "SongTitle": { "S": "Scared of My Shadow" } } ], "Count": 2, "ScannedCount": 2, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 0.5 } }

Pour plus d’informations, consultez Utilisation de requêtes dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour interroger une table à l’aide de lectures fortement cohérentes et parcourir l’index par ordre décroissant

L’exemple suivant exécute la même requête que le premier exemple, mais renvoie les résultats dans l’ordre inverse et utilise des lectures fortement cohérentes.

aws dynamodb query \ --table-name MusicCollection \ --projection-expression "SongTitle" \ --key-condition-expression "Artist = :v1" \ --expression-attribute-values file://expression-attributes.json \ --consistent-read \ --no-scan-index-forward \ --return-consumed-capacity TOTAL

Contenu de expression-attributes.json :

{ ":v1": {"S": "No One You Know"} }

Sortie :

{ "Items": [ { "SongTitle": { "S": "Scared of My Shadow" } }, { "SongTitle": { "S": "Call Me Today" } } ], "Count": 2, "ScannedCount": 2, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 1.0 } }

Pour plus d’informations, consultez Utilisation des requêtes dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour filtrer des résultats spécifiques

L’exemple suivant interroge MusicCollection, mais exclut les résultats contenant des valeurs spécifiques dans l’attribut AlbumTitle. Notez que cela n’affecte pas ScannedCount ni ConsumedCapacity, car le filtre est appliqué après la lecture des éléments.

aws dynamodb query \ --table-name MusicCollection \ --key-condition-expression "#n1 = :v1" \ --filter-expression "NOT (#n2 IN (:v2, :v3))" \ --expression-attribute-names file://names.json \ --expression-attribute-values file://values.json \ --return-consumed-capacity TOTAL

Contenu de values.json :

{ ":v1": {"S": "No One You Know"}, ":v2": {"S": "Blue Sky Blues"}, ":v3": {"S": "Greatest Hits"} }

Contenu de names.json :

{ "#n1": "Artist", "#n2": "AlbumTitle" }

Sortie :

{ "Items": [ { "AlbumTitle": { "S": "Somewhat Famous" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Call Me Today" } } ], "Count": 1, "ScannedCount": 2, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 0.5 } }

Pour plus d’informations, consultez Utilisation des requêtes dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 4 : pour extraire uniquement le nombre d’éléments

L’exemple suivant extrait le nombre d’éléments correspondant à la requête, mais n’extrait aucun des éléments eux-mêmes.

aws dynamodb query \ --table-name MusicCollection \ --select COUNT \ --key-condition-expression "Artist = :v1" \ --expression-attribute-values file://expression-attributes.json

Contenu de expression-attributes.json :

{ ":v1": {"S": "No One You Know"} }

Sortie :

{ "Count": 2, "ScannedCount": 2, "ConsumedCapacity": null }

Pour plus d’informations, consultez Utilisation des requêtes dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

Exemple 5 : pour interroger un index

L’exemple suivant interroge l’index secondaire global AlbumTitleIndex. La requête renvoie tous les attributs de la table de base qui ont été projetés dans l’index secondaire local. Notez que lorsque vous interrogez un index secondaire local ou un index secondaire global, vous devez également fournir le nom de la table de base à l’aide du paramètre table-name.

aws dynamodb query \ --table-name MusicCollection \ --index-name AlbumTitleIndex \ --key-condition-expression "Artist = :v1" \ --expression-attribute-values file://expression-attributes.json \ --select ALL_PROJECTED_ATTRIBUTES \ --return-consumed-capacity INDEXES

Contenu de expression-attributes.json :

{ ":v1": {"S": "No One You Know"} }

Sortie :

{ "Items": [ { "AlbumTitle": { "S": "Blue Sky Blues" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Scared of My Shadow" } }, { "AlbumTitle": { "S": "Somewhat Famous" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Call Me Today" } } ], "Count": 2, "ScannedCount": 2, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 0.5, "Table": { "CapacityUnits": 0.0 }, "LocalSecondaryIndexes": { "AlbumTitleIndex": { "CapacityUnits": 0.5 } } } }

Pour plus d’informations, consultez Utilisation des requêtes dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus d’informations sur l’API, consultez Query dans la Référence des commandes AWS CLI .

L'exemple de code suivant montre comment utiliserrestore-table-from-backup.

AWS CLI

Pour restaurer une table DynamoDB à partir d’une sauvegarde existante

L’exemple restore-table-from-backup suivant restaure la table spécifiée à partir d’une sauvegarde existante.

aws dynamodb restore-table-from-backup \ --target-table-name MusicCollection \ --backup-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection2", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": 1576618274.326, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection2", "TableId": "114865c9-5ef3-496c-b4d1-c4cbdd2d44fb", "BillingModeSummary": { "BillingMode": "PROVISIONED" }, "RestoreSummary": { "SourceBackupArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3a", "SourceTableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "RestoreDateTime": 1576616366.715, "RestoreInProgress": true } } }

Pour plus d’informations, consultez Sauvegarde et restauration à la demande pour DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous RestoreTableFromBackupà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserrestore-table-to-point-in-time.

AWS CLI

Pour restaurer une table DynamoDB à un instant dans le passé

L’exemple restore-table-to-point-in-time suivant restaure la table MusicCollection à l’instant spécifié.

aws dynamodb restore-table-to-point-in-time \ --source-table-name MusicCollection \ --target-table-name MusicCollectionRestore \ --restore-date-time 1576622404.0

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollectionRestore", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": 1576623311.86, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollectionRestore", "TableId": "befd9e0e-1843-4dc6-a147-d6d00e85cb1f", "BillingModeSummary": { "BillingMode": "PROVISIONED" }, "RestoreSummary": { "SourceTableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "RestoreDateTime": 1576622404.0, "RestoreInProgress": true } } }

Pour plus d'informations, consultez la section Point-in-Time Recovery for DynamoDB dans le manuel du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserscan.

AWS CLI

Pour analyser une table

L’exemple scan suivant analyse l’intégralité de la table MusicCollection, puis limite les résultats aux chansons de l’artiste « No One You Know ». Pour chaque élément, seuls le titre de l’album et le titre de la chanson sont renvoyés.

aws dynamodb scan \ --table-name MusicCollection \ --filter-expression "Artist = :a" \ --projection-expression "#ST, #AT" \ --expression-attribute-names file://expression-attribute-names.json \ --expression-attribute-values file://expression-attribute-values.json

Contenu de expression-attribute-names.json :

{ "#ST": "SongTitle", "#AT":"AlbumTitle" }

Contenu de expression-attribute-values.json :

{ ":a": {"S": "No One You Know"} }

Sortie :

{ "Count": 2, "Items": [ { "SongTitle": { "S": "Call Me Today" }, "AlbumTitle": { "S": "Somewhat Famous" } }, { "SongTitle": { "S": "Scared of My Shadow" }, "AlbumTitle": { "S": "Blue Sky Blues" } } ], "ScannedCount": 3, "ConsumedCapacity": null }

Pour plus d’informations, consultez Utilisation des analyses dans DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus d’informations sur l’API, consultez Scan dans la Référence des commandes AWS CLI .

L'exemple de code suivant montre comment utilisertag-resource.

AWS CLI

Pour ajouter des balises à une ressource DynamoDB

L'tag-resourceexemple suivant ajoute une key/value paire de balises au MusicCollection tableau.

aws dynamodb tag-resource \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --tags Key=Owner,Value=blueTeam

Cette commande ne produit aucune sortie.

Pour plus d’informations, consultez Balisage pour DynamoDBdans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous TagResourceà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utilisertransact-get-items.

AWS CLI

Pour extraire plusieurs éléments de manière atomique à partir d’une ou de plusieurs tables

L’exemple transact-get-items suivant extrait plusieurs éléments de manière atomique.

aws dynamodb transact-get-items \ --transact-items file://transact-items.json \ --return-consumed-capacity TOTAL

Contenu de transact-items.json :

[ { "Get": { "Key": { "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }, "TableName": "MusicCollection" } }, { "Get": { "Key": { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"} }, "TableName": "MusicCollection" } } ]

Sortie :

{ "ConsumedCapacity": [ { "TableName": "MusicCollection", "CapacityUnits": 4.0, "ReadCapacityUnits": 4.0 } ], "Responses": [ { "Item": { "AlbumTitle": { "S": "Songs About Life" }, "Artist": { "S": "Acme Band" }, "SongTitle": { "S": "Happy Day" } } }, { "Item": { "AlbumTitle": { "S": "Somewhat Famous" }, "Artist": { "S": "No One You Know" }, "SongTitle": { "S": "Call Me Today" } } } ] }

Pour plus d’informations, consultez Gestion des flux de travail complexes avec Amazon DynamoDB Transactions dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous TransactGetItemsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utilisertransact-write-items.

AWS CLI

Exemple 1 : pour écrire des éléments de manière atomique dans une ou plusieurs tables

L’exemple transact-write-items suivant met à jour un élément et en supprime un autre. L’opération échoue si l’une des opérations échoue ou si l’un des éléments contient un attribut Rating.

aws dynamodb transact-write-items \ --transact-items file://transact-items.json \ --return-consumed-capacity TOTAL \ --return-item-collection-metrics SIZE

Contenu du fichier transact-items.json :

[ { "Update": { "Key": { "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }, "UpdateExpression": "SET AlbumTitle = :newval", "ExpressionAttributeValues": { ":newval": {"S": "Updated Album Title"} }, "TableName": "MusicCollection", "ConditionExpression": "attribute_not_exists(Rating)" } }, { "Delete": { "Key": { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"} }, "TableName": "MusicCollection", "ConditionExpression": "attribute_not_exists(Rating)" } } ]

Sortie :

{ "ConsumedCapacity": [ { "TableName": "MusicCollection", "CapacityUnits": 10.0, "WriteCapacityUnits": 10.0 } ], "ItemCollectionMetrics": { "MusicCollection": [ { "ItemCollectionKey": { "Artist": { "S": "No One You Know" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] }, { "ItemCollectionKey": { "Artist": { "S": "Acme Band" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] } ] } }

Pour plus d’informations, consultez Gestion des flux de travail complexes avec Amazon DynamoDB Transactions dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour écrire des éléments de manière atomique à l’aide d’un jeton de demande client

La commande suivante utilise un jeton de demande client pour appeler des transact-write-items idempotents, ce qui signifie que plusieurs appels ont le même effet qu’un seul appel.

aws dynamodb transact-write-items \ --transact-items file://transact-items.json \ --client-request-token abc123

Contenu du fichier transact-items.json :

[ { "Update": { "Key": { "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }, "UpdateExpression": "SET AlbumTitle = :newval", "ExpressionAttributeValues": { ":newval": {"S": "Updated Album Title"} }, "TableName": "MusicCollection", "ConditionExpression": "attribute_not_exists(Rating)" } }, { "Delete": { "Key": { "Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"} }, "TableName": "MusicCollection", "ConditionExpression": "attribute_not_exists(Rating)" } } ]

Cette commande ne produit aucune sortie.

Pour plus d’informations, consultez Gestion des flux de travail complexes avec Amazon DynamoDB Transactions dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous TransactWriteItemsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliseruntag-resource.

AWS CLI

Pour supprimer une balise d’une ressource DynamoDB

L’exemple untag-resource suivant supprime la balise avec la clé Owner de la table MusicCollection.

aws dynamodb untag-resource \ --resource-arn arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection \ --tag-keys Owner

Cette commande ne produit aucune sortie.

Pour plus d’informations, consultez Balisage pour DynamoDBdans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UntagResourceà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserupdate-continuous-backups.

AWS CLI

Pour mettre à jour les paramètres de sauvegarde continue d’une table DynamoDB

L'update-continuous-backupsexemple suivant active la point-in-time restauration de la MusicCollection table.

aws dynamodb update-continuous-backups \ --table-name MusicCollection \ --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true

Sortie :

{ "ContinuousBackupsDescription": { "ContinuousBackupsStatus": "ENABLED", "PointInTimeRecoveryDescription": { "PointInTimeRecoveryStatus": "ENABLED", "EarliestRestorableDateTime": 1576622404.0, "LatestRestorableDateTime": 1576622404.0 } } }

Pour plus d'informations, consultez la section Point-in-Time Recovery for DynamoDB dans le manuel du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UpdateContinuousBackupsà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserupdate-contributor-insights.

AWS CLI

Pour activer Contributor Insights sur une table

L’exemple update-contributor-insights suivant active Contributor Insights sur la table MusicCollection et l’index secondaire global AlbumTitle-index.

aws dynamodb update-contributor-insights \ --table-name MusicCollection \ --index-name AlbumTitle-index \ --contributor-insights-action ENABLE

Sortie :

{ "TableName": "MusicCollection", "IndexName": "AlbumTitle-index", "ContributorInsightsStatus": "ENABLING" }

Pour plus d'informations, consultez la section Analyse de l'accès aux données à l'aide de CloudWatch Contributor Insights for DynamoDB dans le manuel du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserupdate-global-table-settings.

AWS CLI

Pour mettre à jour les paramètres de capacité d’écriture allouée sur une table globale DynamoDB

L’exemple update-global-table-settings suivant définit la capacité d’écriture allouée de la table globale MusicCollection sur 15.

aws dynamodb update-global-table-settings \ --global-table-name MusicCollection \ --global-table-provisioned-write-capacity-units 15

Sortie :

{ "GlobalTableName": "MusicCollection", "ReplicaSettings": [ { "RegionName": "eu-west-1", "ReplicaStatus": "UPDATING", "ReplicaProvisionedReadCapacityUnits": 10, "ReplicaProvisionedReadCapacityAutoScalingSettings": { "AutoScalingDisabled": true }, "ReplicaProvisionedWriteCapacityUnits": 10, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "AutoScalingDisabled": true } }, { "RegionName": "us-east-1", "ReplicaStatus": "UPDATING", "ReplicaProvisionedReadCapacityUnits": 10, "ReplicaProvisionedReadCapacityAutoScalingSettings": { "AutoScalingDisabled": true }, "ReplicaProvisionedWriteCapacityUnits": 10, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "AutoScalingDisabled": true } }, { "RegionName": "us-east-2", "ReplicaStatus": "UPDATING", "ReplicaProvisionedReadCapacityUnits": 10, "ReplicaProvisionedReadCapacityAutoScalingSettings": { "AutoScalingDisabled": true }, "ReplicaProvisionedWriteCapacityUnits": 10, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "AutoScalingDisabled": true } } ] }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserupdate-global-table.

AWS CLI

Pour mettre à jour une table globale DynamoDB

L’exemple update-global-table suivant ajoute un réplica dans la région spécifiée à la table globale MusicCollection.

aws dynamodb update-global-table \ --global-table-name MusicCollection \ --replica-updates Create={RegionName=eu-west-1}

Sortie :

{ "GlobalTableDescription": { "ReplicationGroup": [ { "RegionName": "eu-west-1" }, { "RegionName": "us-east-2" }, { "RegionName": "us-east-1" } ], "GlobalTableArn": "arn:aws:dynamodb::123456789012:global-table/MusicCollection", "CreationDateTime": 1576625818.532, "GlobalTableStatus": "ACTIVE", "GlobalTableName": "MusicCollection" } }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UpdateGlobalTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserupdate-item.

AWS CLI

Exemple 1 : pour mettre à jour un élément dans une table

L’exemple update-item suivant met à jour un élément dans la table MusicCollection. Il ajoute un nouvel attribut (Year) et modifie l’attribut AlbumTitle. Tous les attributs de l’élément, tels qu’ils apparaissent après la mise à jour, sont renvoyés dans la réponse.

aws dynamodb update-item \ --table-name MusicCollection \ --key file://key.json \ --update-expression "SET #Y = :y, #AT = :t" \ --expression-attribute-names file://expression-attribute-names.json \ --expression-attribute-values file://expression-attribute-values.json \ --return-values ALL_NEW \ --return-consumed-capacity TOTAL \ --return-item-collection-metrics SIZE

Contenu de key.json :

{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }

Contenu de expression-attribute-names.json :

{ "#Y":"Year", "#AT":"AlbumTitle" }

Contenu de expression-attribute-values.json :

{ ":y":{"N": "2015"}, ":t":{"S": "Louder Than Ever"} }

Sortie :

{ "Attributes": { "AlbumTitle": { "S": "Louder Than Ever" }, "Awards": { "N": "10" }, "Artist": { "S": "Acme Band" }, "Year": { "N": "2015" }, "SongTitle": { "S": "Happy Day" } }, "ConsumedCapacity": { "TableName": "MusicCollection", "CapacityUnits": 3.0 }, "ItemCollectionMetrics": { "ItemCollectionKey": { "Artist": { "S": "Acme Band" } }, "SizeEstimateRangeGB": [ 0.0, 1.0 ] } }

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour mettre à jour un élément sous certaines conditions

L’exemple suivant met à jour un élément de la table MusicCollection, mais uniquement si l’élément existant ne possède pas encore d’attribut Year.

aws dynamodb update-item \ --table-name MusicCollection \ --key file://key.json \ --update-expression "SET #Y = :y, #AT = :t" \ --expression-attribute-names file://expression-attribute-names.json \ --expression-attribute-values file://expression-attribute-values.json \ --condition-expression "attribute_not_exists(#Y)"

Contenu de key.json :

{ "Artist": {"S": "Acme Band"}, "SongTitle": {"S": "Happy Day"} }

Contenu de expression-attribute-names.json :

{ "#Y":"Year", "#AT":"AlbumTitle" }

Contenu de expression-attribute-values.json :

{ ":y":{"N": "2015"}, ":t":{"S": "Louder Than Ever"} }

Si l’élément possède déjà un attribut Year, DynamoDB renvoie le résultat suivant.

An error occurred (ConditionalCheckFailedException) when calling the UpdateItem operation: The conditional request failed

Pour plus d’informations, consultez Écriture d’un élément dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UpdateItemà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserupdate-table-replica-auto-scaling.

AWS CLI

Pour mettre à jour les paramètres autoscaling sur les réplicas d’une table globale

L’exemple update-table-replica-auto-scaling suivant met à jour les paramètres autoscaling de capacité d’écriture entre les réplicas de la table globale spécifiée.

aws dynamodb update-table-replica-auto-scaling \ --table-name MusicCollection \ --provisioned-write-capacity-auto-scaling-update file://auto-scaling-policy.json

Contenu de auto-scaling-policy.json :

{ "MinimumUnits": 10, "MaximumUnits": 100, "AutoScalingDisabled": false, "ScalingPolicyUpdate": { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 80 } } }

Sortie :

{ "TableAutoScalingDescription": { "TableName": "MusicCollection", "TableStatus": "ACTIVE", "Replicas": [ { "RegionName": "eu-central-1", "GlobalSecondaryIndexes": [], "ReplicaProvisionedReadCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBReadCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "MinimumUnits": 10, "MaximumUnits": 100, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 80.0 } } ] }, "ReplicaStatus": "ACTIVE" }, { "RegionName": "us-east-1", "GlobalSecondaryIndexes": [], "ReplicaProvisionedReadCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBReadCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "MinimumUnits": 10, "MaximumUnits": 100, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 80.0 } } ] }, "ReplicaStatus": "ACTIVE" }, { "RegionName": "us-east-2", "GlobalSecondaryIndexes": [], "ReplicaProvisionedReadCapacityAutoScalingSettings": { "MinimumUnits": 5, "MaximumUnits": 40000, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBReadCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 70.0 } } ] }, "ReplicaProvisionedWriteCapacityAutoScalingSettings": { "MinimumUnits": 10, "MaximumUnits": 100, "AutoScalingRoleArn": "arn:aws:iam::123456789012:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable", "ScalingPolicies": [ { "PolicyName": "DynamoDBWriteCapacityUtilization:table/MusicCollection", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 80.0 } } ] }, "ReplicaStatus": "ACTIVE" } ] } }

Pour plus d’informations, consultez Tables globales DynamoDB dans le Guide du développeur Amazon DynamoDB.

L'exemple de code suivant montre comment utiliserupdate-table.

AWS CLI

Exemple 1 : pour modifier le mode de facturation d’une table

L’exemple update-table suivant augmente la capacité de lecture et d’écriture provisionnée sur la table MusicCollection.

aws dynamodb update-table \ --table-name MusicCollection \ --billing-mode PROVISIONED \ --provisioned-throughput ReadCapacityUnits=15,WriteCapacityUnits=10

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "UPDATING", "CreationDateTime": "2020-05-26T15:59:49.473000-07:00", "ProvisionedThroughput": { "LastIncreaseDateTime": "2020-07-28T13:18:18.921000-07:00", "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 15, "WriteCapacityUnits": 10 }, "TableSizeBytes": 182, "ItemCount": 2, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "abcd0123-01ab-23cd-0123-abcdef123456", "BillingModeSummary": { "BillingMode": "PROVISIONED", "LastUpdateToPayPerRequestDateTime": "2020-07-28T13:14:48.366000-07:00" } } }

Pour plus d’informations, consultez Mise à jour d’une table dans le Guide du développeur Amazon DynamoDB.

Exemple 2 : pour créer un index secondaire global

L’exemple suivant ajoute un index secondaire global à la table MusicCollection.

aws dynamodb update-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=AlbumTitle,AttributeType=S \ --global-secondary-index-updates file://gsi-updates.json

Contenu de gsi-updates.json :

[ { "Create": { "IndexName": "AlbumTitle-index", "KeySchema": [ { "AttributeName": "AlbumTitle", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 10, "WriteCapacityUnits": 10 }, "Projection": { "ProjectionType": "ALL" } } } ]

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "UPDATING", "CreationDateTime": "2020-05-26T15:59:49.473000-07:00", "ProvisionedThroughput": { "LastIncreaseDateTime": "2020-07-28T12:59:17.537000-07:00", "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 15, "WriteCapacityUnits": 10 }, "TableSizeBytes": 182, "ItemCount": 2, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "abcd0123-01ab-23cd-0123-abcdef123456", "BillingModeSummary": { "BillingMode": "PROVISIONED", "LastUpdateToPayPerRequestDateTime": "2020-07-28T13:14:48.366000-07:00" }, "GlobalSecondaryIndexes": [ { "IndexName": "AlbumTitle-index", "KeySchema": [ { "AttributeName": "AlbumTitle", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "ALL" }, "IndexStatus": "CREATING", "Backfilling": false, "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 10 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitle-index" } ] } }

Pour plus d’informations, consultez Mise à jour d’une table dans le Guide du développeur Amazon DynamoDB.

Exemple 3 : pour activer DynamoDB Streams sur une table

La commande suivante active DynamoDB Streams sur la table MusicCollection.

aws dynamodb update-table \ --table-name MusicCollection \ --stream-specification StreamEnabled=true,StreamViewType=NEW_IMAGE

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "UPDATING", "CreationDateTime": "2020-05-26T15:59:49.473000-07:00", "ProvisionedThroughput": { "LastIncreaseDateTime": "2020-07-28T12:59:17.537000-07:00", "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 15, "WriteCapacityUnits": 10 }, "TableSizeBytes": 182, "ItemCount": 2, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "abcd0123-01ab-23cd-0123-abcdef123456", "BillingModeSummary": { "BillingMode": "PROVISIONED", "LastUpdateToPayPerRequestDateTime": "2020-07-28T13:14:48.366000-07:00" }, "LocalSecondaryIndexes": [ { "IndexName": "AlbumTitleIndex", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "AlbumTitle", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "Year", "Genre" ] }, "IndexSizeBytes": 139, "ItemCount": 2, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitleIndex" } ], "GlobalSecondaryIndexes": [ { "IndexName": "AlbumTitle-index", "KeySchema": [ { "AttributeName": "AlbumTitle", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "ALL" }, "IndexStatus": "ACTIVE", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 10 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitle-index" } ], "StreamSpecification": { "StreamEnabled": true, "StreamViewType": "NEW_IMAGE" }, "LatestStreamLabel": "2020-07-28T21:53:39.112", "LatestStreamArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/stream/2020-07-28T21:53:39.112" } }

Pour plus d’informations, consultez Mise à jour d’une table dans le Guide du développeur Amazon DynamoDB.

Exemple 4 : pour activer le chiffrement côté serveur

L’exemple suivant active le chiffrement côté serveur sur la table MusicCollection.

aws dynamodb update-table \ --table-name MusicCollection \ --sse-specification Enabled=true,SSEType=KMS

Sortie :

{ "TableDescription": { "AttributeDefinitions": [ { "AttributeName": "AlbumTitle", "AttributeType": "S" }, { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "MusicCollection", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "ACTIVE", "CreationDateTime": "2020-05-26T15:59:49.473000-07:00", "ProvisionedThroughput": { "LastIncreaseDateTime": "2020-07-28T12:59:17.537000-07:00", "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 15, "WriteCapacityUnits": 10 }, "TableSizeBytes": 182, "ItemCount": 2, "TableArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection", "TableId": "abcd0123-01ab-23cd-0123-abcdef123456", "BillingModeSummary": { "BillingMode": "PROVISIONED", "LastUpdateToPayPerRequestDateTime": "2020-07-28T13:14:48.366000-07:00" }, "LocalSecondaryIndexes": [ { "IndexName": "AlbumTitleIndex", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "AlbumTitle", "KeyType": "RANGE" } ], "Projection": { "ProjectionType": "INCLUDE", "NonKeyAttributes": [ "Year", "Genre" ] }, "IndexSizeBytes": 139, "ItemCount": 2, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitleIndex" } ], "GlobalSecondaryIndexes": [ { "IndexName": "AlbumTitle-index", "KeySchema": [ { "AttributeName": "AlbumTitle", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "ALL" }, "IndexStatus": "ACTIVE", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 10, "WriteCapacityUnits": 10 }, "IndexSizeBytes": 0, "ItemCount": 0, "IndexArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/index/AlbumTitle-index" } ], "StreamSpecification": { "StreamEnabled": true, "StreamViewType": "NEW_IMAGE" }, "LatestStreamLabel": "2020-07-28T21:53:39.112", "LatestStreamArn": "arn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/stream/2020-07-28T21:53:39.112", "SSEDescription": { "Status": "UPDATING" } } }

Pour plus d’informations, consultez Mise à jour d’une table dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UpdateTableà la section Référence des AWS CLI commandes.

L'exemple de code suivant montre comment utiliserupdate-time-to-live.

AWS CLI

Pour mettre à jour les paramètres de durée de vie (TTL) d’une table

L’exemple update-time-to-live suivant active la durée de vie au niveau de la table spécifiée.

aws dynamodb update-time-to-live \ --table-name MusicCollection \ --time-to-live-specification Enabled=true,AttributeName=ttl

Sortie :

{ "TimeToLiveSpecification": { "Enabled": true, "AttributeName": "ttl" } }

Pour plus d’informations, consultez Time to Live dans le Guide du développeur Amazon DynamoDB.

  • Pour plus de détails sur l'API, reportez-vous UpdateTimeToLiveà la section Référence des AWS CLI commandes.