Uso de UpdateTable con un AWS SDK o la CLI - Amazon DynamoDB

Uso de UpdateTable con un AWS SDK o la CLI

En los siguientes ejemplos de código, se muestra cómo utilizar UpdateTable.

CLI
AWS CLI

Ejemplo 1: para modificar el modo de facturación de una tabla

El siguiente ejemplo de update-table aumenta la capacidad de lectura y escritura aprovisionada en la tabla MusicCollection.

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

Salida:

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

Para obtener más información, consulte Actualización de una tabla en la Guía para desarrolladores de Amazon DynamoDB.

Ejemplo 5: crear un índice secundario global

En el siguiente ejemplo se añade un índice secundario global a la tabla MusicCollection.

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

Contenidos de gsi-updates.json:

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

Salida:

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

Para obtener más información, consulte Actualización de una tabla en la Guía para desarrolladores de Amazon DynamoDB.

Ejemplo 3: activar DynamoDB Streams en una tabla

El siguiente comando activa DynamoDB Streams en la tabla MusicCollection.

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

Salida:

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

Para obtener más información, consulte Actualización de una tabla en la Guía para desarrolladores de Amazon DynamoDB.

Ejemplo 4: activar el cifrado en el lado del servidor

El siguiente ejemplo activa el cifrado del lado del servidor en la tabla MusicCollection.

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

Salida:

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

Para obtener más información, consulte Actualización de una tabla en la Guía para desarrolladores de Amazon DynamoDB.

  • Para obtener información sobre la API, consulte UpdateTable en la AWS CLI Command Reference.

PowerShell
Herramientas para PowerShell

Ejemplo 1: actualiza el rendimiento aprovisionado de la tabla en cuestión.

Update-DDBTable -TableName "myTable" -ReadCapacity 10 -WriteCapacity 5
  • Para obtener información sobre la API, consulte UpdateTable en la AWS Tools for PowerShell Cmdlet Reference.

Para obtener una lista completa de las guías para desarrolladores del AWS SDK y ejemplos de código, consulte Uso de DynamoDB con un SDK de AWS. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.