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.
Topik
Tindakan
Contoh kode berikut menunjukkan cara menggunakanbatch-get-item.
- AWS CLI
-
Untuk mengambil beberapa item dari tabel
batch-get-itemsContoh berikut membaca beberapa item dariMusicCollectiontabel menggunakan kumpulan tigaGetItempermintaan, dan meminta jumlah unit kapasitas baca yang dikonsumsi oleh operasi. Perintah hanya mengembalikanAlbumTitleatribut.aws dynamodb batch-get-item \ --request-itemsfile://request-items.json\ --return-consumed-capacityTOTALIsi 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 keMusicCollectiontabel menggunakan kumpulan tigaPutItempermintaan. 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-itemsfile://request-items.json\ --return-consumed-capacityINDEXES\ --return-item-collection-metricsSIZEIsi 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.
-
Untuk detail API, lihat BatchWriteItem
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakancreate-backup.
- AWS CLI
-
Untuk membuat cadangan untuk tabel DynamoDB yang ada
create-backupContoh berikut membuat cadanganMusicCollectiontabel.aws dynamodb create-backup \ --table-nameMusicCollection\ --backup-nameMusicCollectionBackupOutput:
{ "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-nameMusicCollection\ --replication-groupRegionName=us-east-2RegionName=us-east-1\ --regionus-east-2Output:
{ "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.
-
Untuk detail API, lihat CreateGlobalTable
di Refer AWS CLI ensi Perintah.
-
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 kunciOwnerdan nilaiblueTeam.aws dynamodb create-table \ --table-nameMusicCollection\ --attribute-definitionsAttributeName=Artist,AttributeType=SAttributeName=SongTitle,AttributeType=S\ --key-schemaAttributeName=Artist,KeyType=HASHAttributeName=SongTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=5,WriteCapacityUnits=5\ --tagsKey=Owner,Value=blueTeamOutput:
{ "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
MusicCollectionmenggunakan mode on-demand, bukan mode throughput yang disediakan. Ini berguna untuk tabel dengan beban kerja yang tidak dapat diprediksi.aws dynamodb create-table \ --table-nameMusicCollection\ --attribute-definitionsAttributeName=Artist,AttributeType=SAttributeName=SongTitle,AttributeType=S\ --key-schemaAttributeName=Artist,KeyType=HASHAttributeName=SongTitle,KeyType=RANGE\ --billing-modePAY_PER_REQUESTOutput:
{ "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
MusicCollectiondan mengenkripsinya menggunakan CMK yang dikelola pelanggan.aws dynamodb create-table \ --table-nameMusicCollection\ --attribute-definitionsAttributeName=Artist,AttributeType=SAttributeName=SongTitle,AttributeType=S\ --key-schemaAttributeName=Artist,KeyType=HASHAttributeName=SongTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=5,WriteCapacityUnits=5\ --sse-specificationEnabled=true,SSEType=KMS,KMSMasterKeyId=abcd1234-abcd-1234-a123-ab1234a1b234Output:
{ "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
MusicCollectiondengan Indeks Sekunder Lokal bernamaAlbumTitleIndex.aws dynamodb create-table \ --table-nameMusicCollection\ --attribute-definitionsAttributeName=Artist,AttributeType=SAttributeName=SongTitle,AttributeType=SAttributeName=AlbumTitle,AttributeType=S\ --key-schemaAttributeName=Artist,KeyType=HASHAttributeName=SongTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=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
GameScoresdengan Indeks Sekunder Global yang dipanggilGameTitleIndex. Tabel dasar memiliki kunci partisiUserIddan kunci urutanGameTitle, sehingga Anda dapat menemukan skor terbaik pengguna individu untuk game tertentu secara efisien, sedangkan GSI memiliki kunci partisiGameTitledan kunci urutanTopScore, memungkinkan Anda untuk cepat menemukan skor tertinggi secara keseluruhan untuk game tertentu.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=SAttributeName=TopScore,AttributeType=N\ --key-schemaAttributeName=UserId,KeyType=HASH\AttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=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
GameScoresdengan dua Indeks Sekunder Global. Skema GSI dilewatkan melalui file, bukan pada baris perintah.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=SAttributeName=TopScore,AttributeType=NAttributeName=Date,AttributeType=S\ --key-schemaAttributeName=UserId,KeyType=HASHAttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=10,WriteCapacityUnits=5\ --global-secondary-indexesfile://gsi.jsonIsi 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
GameScoresdengan DynamoDB Streams diaktifkan. Gambar baru dan lama dari setiap item akan ditulis ke streaming.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=S\ --key-schemaAttributeName=UserId,KeyType=HASHAttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=10,WriteCapacityUnits=5\ --stream-specificationStreamEnabled=TRUE,StreamViewType=NEW_AND_OLD_IMAGESOutput:
{ "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
GameScoresdengan DynamoDB Streams diaktifkan. Hanya atribut kunci dari item yang dimodifikasi yang ditulis ke aliran.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=S\ --key-schemaAttributeName=UserId,KeyType=HASHAttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=10,WriteCapacityUnits=5\ --stream-specificationStreamEnabled=TRUE,StreamViewType=KEYS_ONLYOutput:
{ "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
GameScoresdan menetapkan kelas tabel Standard-Infrequent Access (DynamoDB Standard-IA). Kelas tabel ini dioptimalkan untuk penyimpanan menjadi biaya dominan.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=S\ --key-schemaAttributeName=UserId,KeyType=HASHAttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=10,WriteCapacityUnits=5\ --table-classSTANDARD_INFREQUENT_ACCESSOutput:
{ "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
GameScoresdan mengaktifkan perlindungan penghapusan.aws dynamodb create-table \ --table-nameGameScores\ --attribute-definitionsAttributeName=UserId,AttributeType=SAttributeName=GameTitle,AttributeType=S\ --key-schemaAttributeName=UserId,KeyType=HASHAttributeName=GameTitle,KeyType=RANGE\ --provisioned-throughputReadCapacityUnits=10,WriteCapacityUnits=5\ --deletion-protection-enabledOutput:
{ "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-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3aOutput:
{ "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 dariMusicCollectiontabel dan meminta detail tentang item yang dihapus dan kapasitas yang digunakan oleh permintaan.aws dynamodb delete-item \ --table-nameMusicCollection\ --keyfile://key.json\ --return-valuesALL_OLD\ --return-consumed-capacityTOTAL\ --return-item-collection-metricsSIZEIsi 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
ProductCatalogtabel hanya jika item tersebutProductCategoryadalah salah satuSporting GoodsatauGardening Suppliesdan harganya antara 500 dan 600. Ini mengembalikan detail tentang item yang telah dihapus.aws dynamodb delete-item \ --table-nameProductCatalog\ --key '{"Id":{"N":"456"}}' \ --condition-expression"(ProductCategory IN (:cat1, :cat2)) and (#P between :lo and :hi)"\ --expression-attribute-namesfile://names.json\ --expression-attribute-valuesfile://values.json\ --return-valuesALL_OLDIsi 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 menghapusMusicCollectiontabel.aws dynamodb delete-table \ --table-nameMusicCollectionOutput:
{ "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-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3aOutput:
{ "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.
-
Untuk detail API, lihat DescribeBackup
di Refer AWS CLI ensi Perintah.
-
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 untukMusicCollectiontabel.aws dynamodb describe-continuous-backups \ --table-nameMusicCollectionOutput:
{ "ContinuousBackupsDescription": { "ContinuousBackupsStatus": "ENABLED", "PointInTimeRecoveryDescription": { "PointInTimeRecoveryStatus": "DISABLED" } } }Untuk informasi selengkapnya, lihat Pem Point-in-Time ulihan untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat DescribeContinuousBackups
di Refer AWS CLI ensi Perintah.
-
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 untukMusicCollectiontabel dan indeks sekunderAlbumTitle-indexglobal.aws dynamodb describe-contributor-insights \ --table-nameMusicCollection\ --index-nameAlbumTitle-indexOutput:
{ "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.
-
Untuk detail API, lihat DescribeContributorInsights
di Refer AWS CLI ensi Perintah.
-
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-endpointsOutput:
{ "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
-
Untuk detail API, lihat DescribeEndpoints
di Refer AWS CLI ensi Perintah.
-
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 tabelMusicCollectionglobal.aws dynamodb describe-global-table-settings \ --global-table-nameMusicCollectionOutput:
{ "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.
-
Untuk detail API, lihat DescribeGlobalTableSettings
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakandescribe-global-table.
- AWS CLI
-
Untuk menampilkan informasi tentang tabel global DynamoDB
describe-global-tableContoh berikut menampilkan detail tentang tabelMusicCollectionglobal.aws dynamodb describe-global-table \ --global-table-nameMusicCollectionOutput:
{ "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.
-
Untuk detail API, lihat DescribeGlobalTable
di Refer AWS CLI ensi Perintah.
-
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. AWSaws dynamodb describe-limitsOutput:
{ "AccountMaxReadCapacityUnits": 80000, "AccountMaxWriteCapacityUnits": 80000, "TableMaxReadCapacityUnits": 40000, "TableMaxWriteCapacityUnits": 40000 }Untuk informasi selengkapnya, lihat B atas di DynamoDB di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat DescribeLimits
di Refer AWS CLI ensi Perintah.
-
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 tabelMusicCollectionglobal.aws dynamodb describe-table-replica-auto-scaling \ --table-nameMusicCollectionOutput:
{ "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.
-
Untuk detail API, lihat DescribeTableReplicaAutoScaling
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakandescribe-table.
- AWS CLI
-
Untuk menggambarkan tabel
describe-tableContoh berikut menjelaskanMusicCollectiontabel.aws dynamodb describe-table \ --table-nameMusicCollectionOutput:
{ "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.
-
Untuk detail API, lihat DescribeTable
di Refer AWS CLI ensi Perintah.
-
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 untukMusicCollectiontabel.aws dynamodb describe-time-to-live \ --table-nameMusicCollectionOutput:
{ "TimeToLiveDescription": { "TimeToLiveStatus": "ENABLED", "AttributeName": "ttl" } }Untuk informasi selengkapnya, lihat Waktu untuk Hidup di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat DescribeTimeToLive
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakanget-item.
- AWS CLI
-
Contoh 1: Untuk membaca item dalam tabel
get-itemContoh berikut mengambil item dariMusicCollectiontabel. 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-nameMusicCollection\ --keyfile://key.json\ --return-consumed-capacityTOTALIsi 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
MusicCollectiontabel menggunakan pembacaan yang sangat konsisten.aws dynamodb get-item \ --table-nameMusicCollection\ --keyfile://key.json\ --consistent-read \ --return-consumed-capacityTOTALIsi 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-nameProductCatalog\ --key '{"Id": {"N": "102"}}' \ --projection-expression"#T, #C, #P"\ --expression-attribute-namesfile://names.jsonIsi 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-backupsOutput:
{ "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
MusicCollectiontabel 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-nameMusicCollection\ --time-range-lower-bound1577836800\ --time-range-upper-bound1583020800\ --backup-typeUSEROutput:
{ "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-size1Output:
{ "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
NextTokennilai yang digunakan untuk mengambil halaman hasil berikutnya.aws dynamodb list-backups \ --max-items1Output:
{ "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
NextTokennilai dari panggilan sebelumnya kelist-backupsperintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasukNextTokennilai, kita tahu bahwa kita telah mencapai akhir hasil.aws dynamodb list-backups \ --starting-tokenabCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9Output
{ "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-insightsOutput:
{ "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
NextTokennilai yang digunakan untuk mengambil halaman hasil berikutnya.aws dynamodb list-contributor-insights \ --max-results4Output:
{ "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
NextTokennilai dari panggilan sebelumnya kelist-contributor-insightsperintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasukNextTokennilai, kita tahu bahwa kita telah mencapai akhir hasil.aws dynamodb list-contributor-insights \ --max-results4\ --next-tokenabCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9Output:
{ "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.
-
Untuk detail API, lihat ListContributorInsights
di Refer AWS CLI ensi Perintah.
-
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-tablesOutput:
{ "GlobalTables": [ { "GlobalTableName": "MusicCollection", "ReplicationGroup": [ { "RegionName": "us-east-2" }, { "RegionName": "us-east-1" } ] } ] }Untuk informasi selengkapnya, lihat Tabel Global DynamoDB di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat ListGlobalTables
di Refer AWS CLI ensi Perintah.
-
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-tablesOutput:
{ "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-size1Output:
{ "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
NextTokennilai yang digunakan untuk mengambil halaman hasil berikutnya.aws dynamodb list-tables \ --max-items2Output:
{ "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
NextTokennilai dari panggilan sebelumnya kelist-tablesperintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasukNextTokennilai, kita tahu bahwa kita telah mencapai akhir hasil.aws dynamodb list-tables \ --starting-tokenabCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9Output:
{ "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 untukMusicCollectiontabel.aws dynamodb list-tags-of-resource \ --resource-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollectionOutput:
{ "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
NextTokennilai yang digunakan untuk mengambil halaman hasil berikutnya.aws dynamodb list-tags-of-resource \ --resource-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection\ --max-items1Output:
{ "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
NextTokennilai dari panggilan sebelumnya kelist-tags-of-resourceperintah untuk mengambil halaman hasil lain. Karena respons dalam hal ini tidak termasukNextTokennilai, kita tahu bahwa kita telah mencapai akhir hasil.aws dynamodb list-tags-of-resource \ --resource-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection\ --starting-tokenabCDeFGhiJKlmnOPqrSTuvwxYZ1aBCdEFghijK7LM51nOpqRSTuv3WxY3ZabC5dEFGhI2Jk3LmnoPQ6RST9Output:
{ "Tags": [ { "Key": "Environment", "Value": "Production" } ] }Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat ListTagsOfResource
di Refer AWS CLI ensi Perintah.
-
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-nameMusicCollection\ --itemfile://item.json\ --return-consumed-capacityTOTAL\ --return-item-collection-metricsSIZEIsi 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 dalamMusicCollectiontabel hanya jika item yang ada memilikiAlbumTitleatribut dengan nilaiGreatest Hits. Perintah mengembalikan nilai item sebelumnya.aws dynamodb put-item \ --table-nameMusicCollection\ --itemfile://item.json\ --condition-expression"#A = :A"\ --expression-attribute-namesfile://names.json\ --expression-attribute-valuesfile://values.json\ --return-valuesALL_OLDIsi 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 dalamMusicCollectiontabel. 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-nameMusicCollection\ --projection-expression"SongTitle"\ --key-condition-expression"Artist = :v1"\ --expression-attribute-valuesfile://expression-attributes.json\ --return-consumed-capacityTOTALIsi 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-nameMusicCollection\ --projection-expression"SongTitle"\ --key-condition-expression"Artist = :v1"\ --expression-attribute-valuesfile://expression-attributes.json\ --consistent-read \ --no-scan-index-forward \ --return-consumed-capacityTOTALIsi 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
MusicCollectiontetapi mengecualikan dengan nilai tertentu dalamAlbumTitleatribut. Perhatikan bahwa ini tidak mempengaruhiScannedCountatauConsumedCapacity, karena filter diterapkan setelah item telah dibaca.aws dynamodb query \ --table-nameMusicCollection\ --key-condition-expression"#n1 = :v1"\ --filter-expression"NOT (#n2 IN (:v2, :v3))"\ --expression-attribute-namesfile://names.json\ --expression-attribute-valuesfile://values.json\ --return-consumed-capacityTOTALIsi 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-nameMusicCollection\ --selectCOUNT\ --key-condition-expression"Artist = :v1"\ --expression-attribute-valuesfile://expression-attributes.jsonIsi 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 lokal
AlbumTitleIndex. 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 menggunakantable-nameparameter.aws dynamodb query \ --table-nameMusicCollection\ --index-nameAlbumTitleIndex\ --key-condition-expression"Artist = :v1"\ --expression-attribute-valuesfile://expression-attributes.json\ --selectALL_PROJECTED_ATTRIBUTES\ --return-consumed-capacityINDEXESIsi 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-nameMusicCollection\ --backup-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection/backup/01576616366715-b4e58d3aOutput:
{ "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.
-
Untuk detail API, lihat RestoreTableFromBackup
di Refer AWS CLI ensi Perintah.
-
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 mengembalikanMusicCollectiontabel ke titik waktu yang ditentukan.aws dynamodb restore-table-to-point-in-time \ --source-table-nameMusicCollection\ --target-table-nameMusicCollectionRestore\ --restore-date-time1576622404.0Output:
{ "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.
-
Untuk detail API, lihat RestoreTableToPointInTime
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakanscan.
- AWS CLI
-
Untuk memindai tabel
scanContoh berikut memindai seluruhMusicCollectiontabel, 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-nameMusicCollection\ --filter-expression"Artist = :a"\ --projection-expression"#ST, #AT"\ --expression-attribute-namesfile://expression-attribute-names.json\ --expression-attribute-valuesfile://expression-attribute-values.jsonIsi 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 keMusicCollectiontabel.aws dynamodb tag-resource \ --resource-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection\ --tagsKey=Owner,Value=blueTeamPerintah 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-itemsfile://transact-items.json\ --return-consumed-capacityTOTALIsi 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.
-
Untuk detail API, lihat TransactGetItems
di Refer AWS CLI ensi Perintah.
-
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 berisiRatingatribut.aws dynamodb transact-write-items \ --transact-itemsfile://transact-items.json\ --return-consumed-capacityTOTAL\ --return-item-collection-metricsSIZEIsi
transact-items.jsonfile:[ { "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-itemsidempotent, yang berarti bahwa beberapa panggilan memiliki efek yang sama dengan satu panggilan tunggal.aws dynamodb transact-write-items \ --transact-itemsfile://transact-items.json\ --client-request-tokenabc123Isi
transact-items.jsonfile:[ { "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.
-
Untuk detail API, lihat TransactWriteItems
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakanuntag-resource.
- AWS CLI
-
Untuk menghapus tag dari sumber daya DynamoDB
untag-resourceContoh berikut menghapus tag dengan kunciOwnerdariMusicCollectiontabel.aws dynamodb untag-resource \ --resource-arnarn:aws:dynamodb:us-west-2:123456789012:table/MusicCollection\ --tag-keysOwnerPerintah ini tidak menghasilkan output.
Untuk informasi selengkapnya, lihat Men andai untuk DynamoDB di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat UntagResource
di Refer AWS CLI ensi Perintah.
-
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.MusicCollectionaws dynamodb update-continuous-backups \ --table-nameMusicCollection\ --point-in-time-recovery-specificationPointInTimeRecoveryEnabled=trueOutput:
{ "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.
-
Untuk detail API, lihat UpdateContinuousBackups
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakanupdate-contributor-insights.
- AWS CLI
-
Untuk mengaktifkan Wawasan Kontributor pada tabel
update-contributor-insightsContoh berikut mengaktifkan Wawasan Kontributor padaMusicCollectiontabel dan indeks sekunderAlbumTitle-indexglobal.aws dynamodb update-contributor-insights \ --table-nameMusicCollection\ --index-nameAlbumTitle-index\ --contributor-insights-actionENABLEOutput:
{ "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.
-
Untuk detail API, lihat UpdateContributorInsights
di Refer AWS CLI ensi Perintah.
-
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 tabelMusicCollectionglobal menjadi 15.aws dynamodb update-global-table-settings \ --global-table-nameMusicCollection\ --global-table-provisioned-write-capacity-units15Output:
{ "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.
-
Untuk detail API, lihat UpdateGlobalTableSettings
di Refer AWS CLI ensi Perintah.
-
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 tabelMusicCollectionglobal.aws dynamodb update-global-table \ --global-table-nameMusicCollection\ --replica-updatesCreate={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.
-
Untuk detail API, lihat UpdateGlobalTable
di Refer AWS CLI ensi Perintah.
-
Contoh kode berikut menunjukkan cara menggunakanupdate-item.
- AWS CLI
-
Contoh 1: Untuk memperbarui item dalam tabel
Contoh
update-itemberikut memperbarui item dalam tabelMusicCollection. Ini menambahkan atribut baru (Year) dan memodifikasiAlbumTitleatribut. Semua atribut dalam item, seperti yang muncul setelah pembaruan, dikembalikan dalam respons.aws dynamodb update-item \ --table-nameMusicCollection\ --keyfile://key.json\ --update-expression"SET #Y = :y, #AT = :t"\ --expression-attribute-namesfile://expression-attribute-names.json\ --expression-attribute-valuesfile://expression-attribute-values.json\ --return-valuesALL_NEW\ --return-consumed-capacityTOTAL\ --return-item-collection-metricsSIZEIsi 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
MusicCollectiontabel, tetapi hanya jika item yang ada belum memilikiYearatribut.aws dynamodb update-item \ --table-nameMusicCollection\ --keyfile://key.json\ --update-expression"SET #Y = :y, #AT = :t"\ --expression-attribute-namesfile://expression-attribute-names.json\ --expression-attribute-valuesfile://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
Yearatribut, DynamoDB mengembalikan output berikut.An error occurred (ConditionalCheckFailedException) when calling the UpdateItem operation: The conditional request failedUntuk 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-nameMusicCollection\ --provisioned-write-capacity-auto-scaling-updatefile://auto-scaling-policy.jsonIsi 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.
-
Untuk detail API, lihat UpdateTableReplicaAutoScaling
di Refer AWS CLI ensi Perintah.
-
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 padaMusicCollectiontabel.aws dynamodb update-table \ --table-nameMusicCollection\ --billing-modePROVISIONED\ --provisioned-throughputReadCapacityUnits=15,WriteCapacityUnits=10Output:
{ "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
MusicCollectiontabel.aws dynamodb update-table \ --table-nameMusicCollection\ --attribute-definitionsAttributeName=AlbumTitle,AttributeType=S\ --global-secondary-index-updatesfile://gsi-updates.jsonIsi 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.
MusicCollectionaws dynamodb update-table \ --table-nameMusicCollection\ --stream-specificationStreamEnabled=true,StreamViewType=NEW_IMAGEOutput:
{ "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.
MusicCollectionaws dynamodb update-table \ --table-nameMusicCollection\ --sse-specificationEnabled=true,SSEType=KMSOutput:
{ "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-nameMusicCollection\ --time-to-live-specificationEnabled=true,AttributeName=ttlOutput:
{ "TimeToLiveSpecification": { "Enabled": true, "AttributeName": "ttl" } }Untuk informasi selengkapnya, lihat Waktu untuk Hidup di Panduan Pengembang Amazon DynamoDB.
-
Untuk detail API, lihat UpdateTimeToLive
di Refer AWS CLI ensi Perintah.
-