View a markdown version of this page

contoh DynamoDB menggunakan AWS CLI - AWS Command Line Interface

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

contoh DynamoDB menggunakan AWS CLI

Contoh kode berikut menunjukkan cara melakukan tindakan dan mengimplementasikan skenario umum dengan menggunakan AWS Command Line Interface dengan DynamoDB.

Tindakan merupakan kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

Tindakan

Contoh kode berikut menunjukkan cara menggunakanbatch-get-item.

AWS CLI

Untuk mengambil beberapa item dari tabel

batch-get-itemsContoh berikut membaca beberapa item dari MusicCollection tabel menggunakan kumpulan tiga GetItem permintaan, dan meminta jumlah unit kapasitas baca yang dikonsumsi oleh operasi. Perintah hanya mengembalikan AlbumTitle atribut.

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

Isi dari 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" } }

Output:

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

Untuk informasi selengkapnya, lihat Oper asi Batch di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat BatchGetItem di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanbatch-write-item.

AWS CLI

Untuk menambahkan beberapa item ke tabel

batch-write-itemContoh berikut menambahkan tiga item baru ke MusicCollection tabel menggunakan kumpulan tiga PutItem permintaan. Ini juga meminta informasi tentang jumlah unit kapasitas tulis yang dikonsumsi oleh operasi dan koleksi item apa pun yang dimodifikasi oleh operasi.

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

Isi dari 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"} } } } ] }

Output:

{ "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 } } } ] }

Untuk informasi selengkapnya, lihat Oper asi Batch di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakancreate-backup.

AWS CLI

Untuk membuat cadangan untuk tabel DynamoDB yang ada

create-backupContoh berikut membuat cadangan MusicCollection tabel.

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat CreateBackup di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakancreate-global-table.

AWS CLI

Untuk membuat tabel global

create-global-tableContoh berikut membuat tabel global dari dua tabel identik di Wilayah yang ditentukan dan terpisah AWS .

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakancreate-table.

AWS CLI

Contoh 1: Untuk membuat tabel dengan tag

create-tableContoh berikut menggunakan atribut dan skema kunci yang ditentukan untuk membuat tabel bernamaMusicCollection. Tabel ini menggunakan throughput yang disediakan dan dienkripsi saat diam menggunakan CMK AWS milik default. Perintah ini juga menerapkan tag ke tabel, dengan kunci Owner dan nilaiblueTeam.

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 2: Untuk membuat tabel dalam On-Demand Mode

Contoh berikut membuat tabel yang disebut MusicCollection menggunakan mode on-demand, bukan mode throughput yang disediakan. Ini berguna untuk tabel dengan beban kerja yang tidak dapat diprediksi.

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

Output:

{ "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" } } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 3: Untuk membuat tabel dan mengenkripsinya dengan CMK yang Dikelola Pelanggan

Contoh berikut membuat tabel bernama MusicCollection dan mengenkripsinya menggunakan CMK yang dikelola pelanggan.

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

Output:

{ "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" } } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 4: Untuk membuat tabel dengan Indeks Sekunder Lokal

Contoh berikut menggunakan atribut dan skema kunci yang ditentukan untuk membuat tabel bernama MusicCollection dengan Indeks Sekunder Lokal bernamaAlbumTitleIndex.

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\"] } } ]"

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 5: Untuk membuat tabel dengan Indeks Sekunder Global

Contoh berikut membuat tabel bernama GameScores dengan Indeks Sekunder Global yang dipanggilGameTitleIndex. Tabel dasar memiliki kunci partisi UserId dan kunci urutan GameTitle, sehingga Anda dapat menemukan skor terbaik pengguna individu untuk game tertentu secara efisien, sedangkan GSI memiliki kunci partisi GameTitle dan kunci urutan TopScore, memungkinkan Anda untuk cepat menemukan skor tertinggi secara keseluruhan untuk game tertentu.

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 } } ]"

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 6: Untuk membuat tabel dengan beberapa Indeks Sekunder Global sekaligus

Contoh berikut membuat tabel bernama GameScores dengan dua Indeks Sekunder Global. Skema GSI dilewatkan melalui file, bukan pada baris perintah.

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

Isi dari 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 } } ]

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 7: Untuk membuat tabel dengan Streams diaktifkan

Contoh berikut membuat tabel yang dipanggil GameScores dengan DynamoDB Streams diaktifkan. Gambar baru dan lama dari setiap item akan ditulis ke streaming.

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Operasi Dasar untuk Tabel dalam Panduan Developer Amazon DynamoDB.

Contoh 8: Untuk membuat tabel dengan Keys-Only Stream diaktifkan

Contoh berikut membuat tabel yang dipanggil GameScores dengan DynamoDB Streams diaktifkan. Hanya atribut kunci dari item yang dimodifikasi yang ditulis ke aliran.

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat Meng ubah pengambilan data untuk Streams DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 9: Untuk membuat tabel dengan kelas Akses Langsung Standar

Contoh berikut membuat tabel yang disebut GameScores dan menetapkan kelas tabel Standard-Infrequent Access (DynamoDB Standard-IA). Kelas tabel ini dioptimalkan untuk penyimpanan menjadi biaya dominan.

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat Kelas Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 10: Membuat tabel dengan Delete Protection diaktifkan

Contoh berikut membuat tabel yang disebut GameScores dan mengaktifkan perlindungan penghapusan.

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat Menggunakan perlindungan penghapusan di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat CreateTable di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakandelete-backup.

AWS CLI

Untuk menghapus cadangan DynamoDB yang ada

delete-backupContoh berikut menghapus cadangan yang ada yang ditentukan.

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

Output:

{ "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": {} } }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat DeleteBackup di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakandelete-item.

AWS CLI

Contoh 1: Untuk menghapus item

delete-itemContoh berikut menghapus item dari MusicCollection tabel dan meminta detail tentang item yang dihapus dan kapasitas yang digunakan oleh permintaan.

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

Isi dari key.json:

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

Output:

{ "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 ] } }

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk menghapus item secara kondisional

Contoh berikut menghapus item dari ProductCatalog tabel hanya jika item tersebut ProductCategory adalah salah satu Sporting Goods atau Gardening Supplies dan harganya antara 500 dan 600. Ini mengembalikan detail tentang item yang telah dihapus.

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

Isi dari names.json:

{ "#P": "Price" }

Isi dari values.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat DeleteItem di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakandelete-table.

AWS CLI

Untuk menghapus tabel

delete-tableContoh berikut menghapus MusicCollection tabel.

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

Output:

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

Untuk informasi selengkapnya, lihat Menghapus Tabel di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat DeleteTable di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakandescribe-backup.

AWS CLI

Untuk mendapatkan informasi tentang cadangan tabel yang ada

describe-backupContoh berikut menampilkan informasi tentang cadangan yang ada yang ditentukan.

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

Output:

{ "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": {} } }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-continuous-backups.

AWS CLI

Untuk mendapatkan informasi tentang pencadangan berkelanjutan untuk tabel DynamoDB

describe-continuous-backupsContoh berikut menampilkan detail tentang pengaturan cadangan berkelanjutan untuk MusicCollection tabel.

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

Output:

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

Untuk informasi selengkapnya, lihat Pem Point-in-Time ulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-contributor-insights.

AWS CLI

Untuk melihat pengaturan Insights Contributor untuk tabel DynamoDB

describe-contributor-insightsContoh berikut menampilkan pengaturan Insights Contributor untuk MusicCollection tabel dan indeks sekunder AlbumTitle-index global.

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

Output:

{ "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 }

Untuk informasi selengkapnya, lihat Meng analisis Akses Data Menggunakan Wawasan CloudWatch Kontributor untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-endpoints.

AWS CLI

Untuk melihat informasi titik akhir regional

describe-endpointsContoh berikut menampilkan detail tentang titik akhir untuk Wil AWS ayah saat ini.

aws dynamodb describe-endpoints

Output:

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

Untuk informasi selengkapnya, lihat T itik Akhir dan Kuota Amazon DynamoDB di Referensi Umum. AWS

Contoh kode berikut menunjukkan cara menggunakandescribe-global-table-settings.

AWS CLI

Untuk mendapatkan informasi tentang pengaturan tabel global DynamoDB

describe-global-table-settingsContoh berikut menampilkan pengaturan untuk tabel MusicCollection global.

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

Output:

{ "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 } } ] }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-global-table.

AWS CLI

Untuk menampilkan informasi tentang tabel global DynamoDB

describe-global-tableContoh berikut menampilkan detail tentang tabel MusicCollection global.

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-limits.

AWS CLI

Untuk melihat batas kapasitas yang disediakan

describe-limitsContoh berikut menampilkan batas kapasitas yang disediakan untuk akun Anda di Wilayah saat ini. AWS

aws dynamodb describe-limits

Output:

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

Untuk informasi selengkapnya, lihat B atas di DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-table-replica-auto-scaling.

AWS CLI

Untuk melihat pengaturan penskalaan otomatis di seluruh replika tabel global

describe-table-replica-auto-scalingContoh berikut menampilkan pengaturan penskalaan otomatis di seluruh replika tabel MusicCollection global.

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

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-table.

AWS CLI

Untuk menggambarkan tabel

describe-tableContoh berikut menjelaskan MusicCollection tabel.

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat Menjelaskan Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakandescribe-time-to-live.

AWS CLI

Untuk melihat pengaturan Time to Live untuk tabel

describe-time-to-liveContoh berikut menampilkan pengaturan Time to Live untuk MusicCollection tabel.

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

Output:

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

Untuk informasi selengkapnya, lihat Waktu untuk Hidup di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanget-item.

AWS CLI

Contoh 1: Untuk membaca item dalam tabel

get-itemContoh berikut mengambil item dari MusicCollection tabel. Tabel memiliki kunci utama hash-and-range (ArtistdanSongTitle), jadi Anda harus menentukan kedua atribut ini. Perintah ini juga meminta informasi tentang kapasitas baca yang dikonsumsi oleh operasi.

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

Isi dari key.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Membaca Item di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Membaca item menggunakan pembacaan yang konsisten

Contoh berikut mengambil item dari MusicCollection tabel menggunakan pembacaan yang sangat konsisten.

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

Isi dari key.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Membaca Item di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk mengambil atribut tertentu dari suatu item

Contoh berikut menggunakan ekspresi proyeksi untuk mengambil hanya tiga atribut dari item yang diinginkan.

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

Isi dari names.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Membaca Item di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat GetItem di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanlist-backups.

AWS CLI

Contoh 1: Untuk membuat daftar semua cadangan DynamoDB yang ada

list-backupsContoh berikut mencantumkan semua cadangan Anda yang ada.

aws dynamodb list-backups

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-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 } ] }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk membuat daftar cadangan yang dibuat pengguna dalam rentang waktu tertentu

Contoh berikut hanya mencantumkan cadangan MusicCollection tabel yang dibuat oleh pengguna (bukan yang dibuat secara otomatis oleh DynamoDB) dengan tanggal pembuatan antara 1 Januari 2020 dan 1 Maret 2020.

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

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-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 } ] }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk membatasi ukuran halaman

Contoh berikut mengembalikan daftar semua cadangan yang ada, tetapi mengambil hanya satu item di setiap panggilan, melakukan beberapa panggilan jika perlu untuk mendapatkan seluruh daftar. Membatasi ukuran halaman berguna saat menjalankan perintah daftar pada sejumlah besar sumber daya, yang dapat mengakibatkan kesalahan “batas waktu” saat menggunakan ukuran halaman default 1000.

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

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-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 } ] }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 4: Untuk membatasi jumlah item yang dikembalikan

Contoh berikut membatasi jumlah item yang dikembalikan ke 1. Respons mencakup NextToken nilai yang digunakan untuk mengambil halaman hasil berikutnya.

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

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-a1bcd234", "BackupName": "MusicCollectionBackup1", "BackupCreationDateTime": "2020-02-12T14:41:51.617000-08:00", "BackupStatus": "AVAILABLE", "BackupType": "USER", "BackupSizeBytes": 170 } ], "NextToken": "abCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9" }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 5: Untuk mengambil halaman hasil berikutnya

Perintah berikut menggunakan NextToken nilai dari panggilan sebelumnya ke list-backups perintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasuk NextToken nilai, kita tahu bahwa kita telah mencapai akhir hasil.

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 } ] }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat ListBackups di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanlist-contributor-insights.

AWS CLI

Contoh 1: Untuk melihat daftar ringkasan Wawasan Kontributor

list-contributor-insightsContoh berikut menampilkan daftar ringkasan Wawasan Kontributor.

aws dynamodb list-contributor-insights

Output:

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

Untuk informasi selengkapnya, lihat Meng analisis Akses Data Menggunakan Wawasan CloudWatch Kontributor untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk membatasi jumlah item yang dikembalikan

Contoh berikut membatasi jumlah item yang dikembalikan menjadi 4. Respons mencakup NextToken nilai yang digunakan untuk mengambil halaman hasil berikutnya.

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

Output:

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

Untuk informasi selengkapnya, lihat Meng analisis Akses Data Menggunakan Wawasan CloudWatch Kontributor untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk mengambil halaman hasil berikutnya

Perintah berikut menggunakan NextToken nilai dari panggilan sebelumnya ke list-contributor-insights perintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasuk NextToken nilai, kita tahu bahwa kita telah mencapai akhir hasil.

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

Output:

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

Untuk informasi selengkapnya, lihat Meng analisis Akses Data Menggunakan Wawasan CloudWatch Kontributor untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanlist-global-tables.

AWS CLI

Untuk membuat daftar tabel global DynamoDB yang ada

list-global-tablesContoh berikut mencantumkan semua tabel global Anda yang ada.

aws dynamodb list-global-tables

Output:

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

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanlist-tables.

AWS CLI

Contoh 1: Untuk membuat daftar tabel

list-tablesContoh berikut mencantumkan semua tabel yang terkait dengan AWS akun saat ini dan Wilayah.

aws dynamodb list-tables

Output:

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

Untuk informasi selengkapnya, lihat Daftar Nama Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk membatasi ukuran halaman

Contoh berikut mengembalikan daftar semua tabel yang ada, tetapi mengambil hanya satu item di setiap panggilan, melakukan beberapa panggilan jika perlu untuk mendapatkan seluruh daftar. Membatasi ukuran halaman berguna saat menjalankan perintah daftar pada sejumlah besar sumber daya, yang dapat mengakibatkan kesalahan “batas waktu” saat menggunakan ukuran halaman default 1000.

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

Output:

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

Untuk informasi selengkapnya, lihat Daftar Nama Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk membatasi jumlah item yang dikembalikan

Contoh berikut membatasi jumlah item yang dikembalikan ke 2. Respons mencakup NextToken nilai yang digunakan untuk mengambil halaman hasil berikutnya.

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

Output:

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

Untuk informasi selengkapnya, lihat Daftar Nama Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 4: Untuk mengambil halaman hasil berikutnya

Perintah berikut menggunakan NextToken nilai dari panggilan sebelumnya ke list-tables perintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasuk NextToken nilai, kita tahu bahwa kita telah mencapai akhir hasil.

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

Output:

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

Untuk informasi selengkapnya, lihat Daftar Nama Tabel di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat ListTables di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanlist-tags-of-resource.

AWS CLI

Contoh 1: Untuk mencantumkan tag sumber daya DynamoDB

list-tags-of-resourceContoh berikut menampilkan tag untuk MusicCollection tabel.

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

Output:

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

Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk membatasi jumlah tag yang dikembalikan

Contoh berikut membatasi jumlah tag yang dikembalikan ke 1. Respons mencakup NextToken nilai yang digunakan untuk mengambil halaman hasil berikutnya.

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

Output:

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

Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk mengambil halaman hasil berikutnya

Perintah berikut menggunakan NextToken nilai dari panggilan sebelumnya ke list-tags-of-resource perintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasuk NextToken nilai, kita tahu bahwa kita telah mencapai akhir hasil.

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

Output:

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

Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanput-item.

AWS CLI

Contoh 1: Untuk menambahkan item ke tabel

put-itemContoh berikut menambahkan item baru ke MusicCollection tabel.

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

Isi dari item.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk mengganti item secara kondisional dalam tabel

put-itemContoh berikut mengganti item yang ada dalam MusicCollection tabel hanya jika item yang ada memiliki AlbumTitle atribut dengan nilaiGreatest Hits. Perintah mengembalikan nilai item sebelumnya.

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

Isi dari item.json:

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

Isi dari names.json:

{ "#A": "AlbumTitle" }

Isi dari values.json:

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

Output:

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

Jika kunci sudah ada, Anda akan melihat output berikut:

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

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat PutItem di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanquery.

AWS CLI

Contoh 1: Untuk menanyakan tabel

queryContoh berikut menanyakan item dalam MusicCollection tabel. Tabel memiliki kunci utama hash-and-range (ArtistdanSongTitle), tetapi kueri ini hanya menentukan nilai kunci hash. Ini mengembalikan judul lagu oleh artis bernama “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

Isi dari expression-attributes.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Bek erja dengan Kueri di DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk menanyakan tabel menggunakan pembacaan yang sangat konsisten dan melintasi indeks dalam urutan menurun

Contoh berikut melakukan kueri yang sama seperti contoh pertama, tetapi mengembalikan hasil dalam urutan terbalik dan menggunakan pembacaan yang sangat konsisten.

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

Isi dari expression-attributes.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Bek erja dengan Kueri di DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk menyaring hasil tertentu

Contoh berikut menanyakan hasil MusicCollection tetapi mengecualikan dengan nilai tertentu dalam AlbumTitle atribut. Perhatikan bahwa ini tidak mempengaruhi ScannedCount atauConsumedCapacity, karena filter diterapkan setelah item telah dibaca.

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

Isi dari values.json:

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

Isi dari names.json:

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

Output:

{ "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 } }

Untuk informasi selengkapnya, lihat Bek erja dengan Kueri di DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 4: Untuk mengambil hanya jumlah item

Contoh berikut mengambil jumlah item yang cocok dengan kueri, tetapi tidak mengambil item itu sendiri.

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

Isi dari expression-attributes.json:

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

Output:

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

Untuk informasi selengkapnya, lihat Bek erja dengan Kueri di DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 5: Untuk menanyakan indeks

Contoh berikut menanyakan indeks sekunder lokalAlbumTitleIndex. Query mengembalikan semua atribut dari tabel dasar yang telah diproyeksikan ke indeks sekunder lokal. Perhatikan bahwa ketika menanyakan indeks sekunder lokal atau indeks sekunder global, Anda juga harus memberikan nama tabel dasar menggunakan table-name parameter.

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

Isi dari expression-attributes.json:

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

Output:

{ "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 } } } }

Untuk informasi selengkapnya, lihat Bek erja dengan Kueri di DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat Kueri di Referensi Perintah AWS CLI .

Contoh kode berikut menunjukkan cara menggunakanrestore-table-from-backup.

AWS CLI

Untuk mengembalikan tabel DynamoDB dari cadangan yang ada

restore-table-from-backupContoh berikut mengembalikan tabel yang ditentukan dari cadangan yang ada.

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

Output:

{ "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 } } }

Untuk informasi selengkapnya, lihat On-Demand Pencadangan dan Pemulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanrestore-table-to-point-in-time.

AWS CLI

Untuk mengembalikan tabel DynamoDB ke titik waktu

restore-table-to-point-in-timeContoh berikut mengembalikan MusicCollection tabel ke titik waktu yang ditentukan.

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

Output:

{ "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 } } }

Untuk informasi selengkapnya, lihat Pem Point-in-Time ulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanscan.

AWS CLI

Untuk memindai tabel

scanContoh berikut memindai seluruh MusicCollection tabel, dan kemudian mempersempit hasilnya ke lagu oleh artis “No One You Know”. Untuk setiap item, hanya judul album dan judul lagu yang dikembalikan.

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

Isi dari expression-attribute-names.json:

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

Isi dari expression-attribute-values.json:

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

Output:

{ "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 }

Untuk informasi selengkapnya, lihat Bek erja dengan Pemindaian di DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat Scan in Referensi Perintah AWS CLI .

Contoh kode berikut menunjukkan cara menggunakantag-resource.

AWS CLI

Untuk menambahkan tag ke sumber daya DynamoDB

tag-resourceContoh berikut menambahkan key/value pasangan tag ke MusicCollection tabel.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat TagResource di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakantransact-get-items.

AWS CLI

Untuk mengambil beberapa item secara atomik dari satu atau lebih tabel

transact-get-itemsContoh berikut mengambil beberapa item secara atomik.

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

Isi dari 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" } } ]

Output:

{ "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" } } } ] }

Untuk informasi selengkapnya, lihat M engelola Alur Kerja Kompleks dengan Transaksi DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakantransact-write-items.

AWS CLI

Contoh 1: Untuk menulis item secara atomik ke satu atau lebih tabel

transact-write-itemsContoh berikut memperbarui satu item dan menghapus yang lain. Operasi gagal jika salah satu operasi gagal, atau jika salah satu item berisi Rating atribut.

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

Isi transact-items.json file:

[ { "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)" } } ]

Output:

{ "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 ] } ] } }

Untuk informasi selengkapnya, lihat M engelola Alur Kerja Kompleks dengan Transaksi DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk menulis item secara atomik menggunakan token permintaan klien

Perintah berikut menggunakan token permintaan klien untuk melakukan panggilan ke transact-write-items idempotent, yang berarti bahwa beberapa panggilan memiliki efek yang sama dengan satu panggilan tunggal.

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

Isi transact-items.json file:

[ { "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)" } } ]

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat M engelola Alur Kerja Kompleks dengan Transaksi DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanuntag-resource.

AWS CLI

Untuk menghapus tag dari sumber daya DynamoDB

untag-resourceContoh berikut menghapus tag dengan kunci Owner dari MusicCollection tabel.

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

Perintah ini tidak menghasilkan output.

Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-continuous-backups.

AWS CLI

Untuk memperbarui pengaturan pencadangan berkelanjutan untuk tabel DynamoDB

update-continuous-backupsContoh berikut memungkinkan pemulihan point-in-time untuk tabel. MusicCollection

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

Output:

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

Untuk informasi selengkapnya, lihat Pem Point-in-Time ulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-contributor-insights.

AWS CLI

Untuk mengaktifkan Wawasan Kontributor pada tabel

update-contributor-insightsContoh berikut mengaktifkan Wawasan Kontributor pada MusicCollection tabel dan indeks sekunder AlbumTitle-index global.

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

Output:

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

Untuk informasi selengkapnya, lihat Meng analisis Akses Data Menggunakan Wawasan CloudWatch Kontributor untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-global-table-settings.

AWS CLI

Untuk memperbarui pengaturan kapasitas tulis yang disediakan pada tabel global DynamoDB

update-global-table-settingsContoh berikut menetapkan kapasitas tulis yang disediakan dari tabel MusicCollection global menjadi 15.

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

Output:

{ "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 } } ] }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-global-table.

AWS CLI

Untuk memperbarui tabel global DynamoDB

update-global-tableContoh berikut menambahkan replika di Wilayah yang ditentukan ke tabel MusicCollection global.

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-item.

AWS CLI

Contoh 1: Untuk memperbarui item dalam tabel

Contoh update-item berikut memperbarui item dalam tabel MusicCollection. Ini menambahkan atribut baru (Year) dan memodifikasi AlbumTitle atribut. Semua atribut dalam item, seperti yang muncul setelah pembaruan, dikembalikan dalam respons.

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

Isi dari key.json:

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

Isi dari expression-attribute-names.json:

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

Isi dari expression-attribute-values.json:

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

Output:

{ "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 ] } }

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk memperbarui item secara kondisional

Contoh berikut memperbarui item dalam MusicCollection tabel, tetapi hanya jika item yang ada belum memiliki Year atribut.

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)"

Isi dari key.json:

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

Isi dari expression-attribute-names.json:

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

Isi dari expression-attribute-values.json:

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

Jika item sudah memiliki Year atribut, DynamoDB mengembalikan output berikut.

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

Untuk informasi selengkapnya, lihat Menulis Item di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat UpdateItem di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanupdate-table-replica-auto-scaling.

AWS CLI

Untuk memperbarui pengaturan penskalaan otomatis di seluruh replika tabel global

update-table-replica-auto-scalingContoh berikut memperbarui pengaturan penskalaan otomatis kapasitas tulis di seluruh replika tabel global yang ditentukan.

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

Isi dari auto-scaling-policy.json:

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

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.

Contoh kode berikut menunjukkan cara menggunakanupdate-table.

AWS CLI

Contoh 1: Untuk mengubah mode penagihan tabel

update-tableContoh berikut meningkatkan kapasitas baca dan tulis yang disediakan pada MusicCollection tabel.

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

Output:

{ "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" } } }

Untuk informasi selengkapnya, lihat Memperbarui Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 2: Untuk membuat indeks sekunder global

Contoh berikut menambahkan indeks sekunder global ke MusicCollection tabel.

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

Isi dari gsi-updates.json:

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

Output:

{ "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" } ] } }

Untuk informasi selengkapnya, lihat Memperbarui Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 3: Untuk mengaktifkan Streams DynamoDB pada tabel

Perintah berikut mengaktifkan Streams DynamoDB pada tabel. MusicCollection

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

Output:

{ "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" } }

Untuk informasi selengkapnya, lihat Memperbarui Tabel di Panduan Pengembang Amazon DynamoDB.

Contoh 4: Untuk mengaktifkan enkripsi sisi server

Contoh berikut mengaktifkan enkripsi sisi server pada tabel. MusicCollection

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

Output:

{ "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" } } }

Untuk informasi selengkapnya, lihat Memperbarui Tabel di Panduan Pengembang Amazon DynamoDB.

  • Untuk detail API, lihat UpdateTable di Refer AWS CLI ensi Perintah.

Contoh kode berikut menunjukkan cara menggunakanupdate-time-to-live.

AWS CLI

Untuk memperbarui pengaturan Time to Live pada tabel

update-time-to-liveContoh berikut mengaktifkan Waktu untuk Hidup pada tabel yang ditentukan.

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

Output:

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

Untuk informasi selengkapnya, lihat Waktu untuk Hidup di Panduan Pengembang Amazon DynamoDB.