

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Funzionamento del throughput di DynamoDB
<a name="warm-throughput"></a>

Il *throughput a caldo* si riferisce al numero di operazioni di lettura e scrittura che la tabella DynamoDB è in grado di supportare in modo istantaneo. Questi valori sono disponibili per impostazione predefinita per tutte le tabelle e gli indici secondari globali (GSI) e rappresentano il dimensionamento attuato in base all’utilizzo storico. Se si utilizza la modalità on demand o se si aggiorna il throughput allocato a questi valori, l’applicazione sarà in grado di emettere richieste fino a tali valori in modo istantaneo.

DynamoDB regolerà automaticamente i valori di throughput a caldo man mano che l’utilizzo aumenta. Puoi anche aumentare questi valori in modo proattivo quando necessario, il che è particolarmente utile per i prossimi eventi di punta come il lancio o la vendita di prodotti. Per gli eventi di picco pianificati, in cui i tassi di richiesta alla tabella DynamoDB potrebbero aumentare di 10, 100 volte o più, ora è possibile valutare se l’attuale throughput a caldo è sufficiente per gestire il traffico previsto. In caso negativo, è possibile aumentare il valore di throughput a caldo senza modificare le impostazioni di throughput o la [modalità di fatturazione](capacity-mode.md). Questo processo, denominato *pre-riscaldamento* di una tabella, consente di impostare una baseline che le tabelle possano supportare in modo istantaneo. Ciò garantisce che le applicazioni siano in grado di gestire tassi di richieste più elevati dal momento in cui si verificano. Una volta aumentati, i valori di resa a caldo non possono essere ridotti.

È possibile aumentare il valore di throughput a caldo per le operazioni di lettura, le operazioni di scrittura o entrambe. È possibile aumentare questo valore per tabelle a regione singola, tabelle globali e nuove ed esistenti. GSIs Per le tabelle globali, questa funzionalità è disponibile per la [versione 2019.11.21 (Corrente)](GlobalTables.md) e le impostazioni di throughput a caldo configurate verranno applicate automaticamente a tutte le tabelle di replica nella tabella globale. Non è previsto alcun limite per il numero di tabelle DynamoDB che è possibile pre-riscaldare in qualsiasi momento. Il tempo necessario per completare il pre-riscaldamento dipende dai valori impostati e dalla dimensione della tabella o dell’indice. È possibile inviare richieste di pre-riscaldamento simultanee e tali richieste non interferiranno con le operazioni della tabella. È possibile preriscaldare il tavolo fino al limite di quota della tabella o dell’indice previsto per l’account in quella Regione. Utilizza la [console Service Quotas](https://console.aws.amazon.com/servicequotas) per controllare i limiti attuali e aumentarli se necessario. 

I valori di throughput a caldo sono disponibili per impostazione predefinita per tutte le tabelle e gli indici secondari senza alcun costo. Tuttavia, se si aumentano in modo proattivo questi valori di throughput caldo predefiniti per pre-riscaldare le tabelle, verranno addebitati i costi per tali richieste. Per ulteriori informazioni, consulta [Prezzi di Amazon DynamoDB](https://aws.amazon.com/dynamodb/pricing/).

Per ulteriori informazioni sul throughput a caldo, consulta gli argomenti riportati di seguito:

**Topics**
+ [Check your DynamoDB table’s current warm throughput](check-warm-throughput.md)
+ [Aumento del throughput a caldo di una tabella DynamoDB esistente](update-warm-throughput.md)
+ [Creazione di una nuova tabella DynamoDB con throughput caldo più elevato](create-table-warm-throughput.md)
+ [Funzionamento del throughput a caldo di DynamoDB in diversi scenari](warm-throughput-scenarios.md)

# Check your DynamoDB table’s current warm throughput
<a name="check-warm-throughput"></a>

Utilizza le seguenti istruzioni AWS CLI e quelle AWS della Console per controllare il valore attuale della velocità effettiva a caldo della tabella o dell'indice.

## Console di gestione AWS
<a name="warm-throughput-check-console"></a>

Per controllare il throughput a caldo di una tabella DynamoDB utilizzando la console DynamoDB:

1. Accedi Console di gestione AWS e apri la console DynamoDB all'indirizzo. [https://console.aws.amazon.com/dynamodb/](https://console.aws.amazon.com/dynamodb/)

1. Nel riquadro di navigazione a sinistra, selezionare Tables (Tabelle).

1. Nella pagina **Tabelle**, seleziona la tabella desiderata.

1. Seleziona **Impostazioni aggiuntive** per visualizzare il valore attuale del throughput a caldo. Questo valore viene visualizzato come unità di lettura al secondo e unità di scrittura al secondo.

## AWS CLI
<a name="warm-throughput-check-CLI"></a>

L' AWS CLI esempio seguente mostra come controllare il throughput a caldo della tabella DynamoDB.

1. Esegui l’operazione `describe-table` sulla tabella DynamoDB.

   ```
   aws dynamodb describe-table --table-name GameScores
   ```

1. Riceverai una risposta simile a quella seguente. Le impostazioni sul `WarmThroughput` verranno visualizzate come `ReadUnitsPerSecond` e`WriteUnitsPerSecond`. `Status` risulterà `UPDATING` quando verrà aggiornato il valore di throughput a caldo e `ACTIVE` quando sarà stato impostato il nuovo valore di throughput a caldo.

   ```
   {
       "Table": {
           "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": "ACTIVE",
           "CreationDateTime": 1726128388.729,
           "ProvisionedThroughput": {
               "NumberOfDecreasesToday": 0,
               "ReadCapacityUnits": 0,
               "WriteCapacityUnits": 0
           },
           "TableSizeBytes": 0,
           "ItemCount": 0,
           "TableArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores",
           "TableId": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
           "BillingModeSummary": {
               "BillingMode": "PAY_PER_REQUEST",
               "LastUpdateToPayPerRequestDateTime": 1726128388.729
           },
           "GlobalSecondaryIndexes": [
               {
                   "IndexName": "GameTitleIndex",
                   "KeySchema": [
                       {
                           "AttributeName": "GameTitle",
                           "KeyType": "HASH"
                       },
                       {
                           "AttributeName": "TopScore",
                           "KeyType": "RANGE"
                       }
                   ],
                   "Projection": {
                       "ProjectionType": "INCLUDE",
                       "NonKeyAttributes": [
                           "UserId"
                       ]
                   },
                   "IndexStatus": "ACTIVE",
                   "ProvisionedThroughput": {
                       "NumberOfDecreasesToday": 0,
                       "ReadCapacityUnits": 0,
                       "WriteCapacityUnits": 0
                   },
                   "IndexSizeBytes": 0,
                   "ItemCount": 0,
                   "IndexArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores/index/GameTitleIndex",
                   "WarmThroughput": {
                       "ReadUnitsPerSecond": 12000,
                       "WriteUnitsPerSecond": 4000,
                       "Status": "ACTIVE"
                   }
               }
           ],
           "DeletionProtectionEnabled": false,
           "WarmThroughput": {
               "ReadUnitsPerSecond": 12000,
               "WriteUnitsPerSecond": 4000,
               "Status": "ACTIVE"
           }
       }
   }
   ```

# Aumento del throughput a caldo di una tabella DynamoDB esistente
<a name="update-warm-throughput"></a>

Dopo aver verificato l’attuale valore di throughput a caldo della tabella DynamoDB, è possibile aggiornarla attraverso la seguente procedura:

## Console di gestione AWS
<a name="warm-throughput-update-console"></a>

Come controllare il valore di throughput a caldo della tabella DynamoDB utilizzando la console DynamoDB:

1. Accedi Console di gestione AWS e apri la console DynamoDB all'indirizzo. [https://console.aws.amazon.com/dynamodb/](https://console.aws.amazon.com/dynamodb/)

1. Nel riquadro di navigazione a sinistra, selezionare Tables (Tabelle).

1. Nella pagina **Tabelle**, seleziona la tabella desiderata.

1. Nel campo **Throughput a caldo**, seleziona **Modifica**.

1. Nella pagina **Modifica il throughput effettivo**, seleziona **Aumentare il throughput a caldo**.

1. Regola le **Unità di lettura al secondo** e le **Unità di scrittura al secondo**. Queste due impostazioni definiscono il throughput che la tabella può gestire in modo istantaneo.

1. Seleziona **Salva**.

1. Le **unità di lettura al secondo** e le **unità di scrittura al secondo** verranno aggiornate nel campo **Throughput a caldo** al termine dell’elaborazione della richiesta.
**Nota**  
L’aggiornamento del valore di throughput caldo è un’operazione asincrona. `Status` cambierà da `UPDATING` a `ACTIVE` quando l’aggiornamento sarà completo.

## AWS CLI
<a name="warm-throughput-update-CLI"></a>

L' AWS CLI esempio seguente mostra come aggiornare il valore di throughput caldo della tabella DynamoDB.

1. Esegui l’operazione `update-table` sulla tabella DynamoDB.

   ```
   aws dynamodb update-table \
       --table-name GameScores \
       --warm-throughput ReadUnitsPerSecond=12345,WriteUnitsPerSecond=4567 \
       --global-secondary-index-updates \
           "[
               {
                   \"Update\": {
                       \"IndexName\": \"GameTitleIndex\",
                       \"WarmThroughput\": {
                           \"ReadUnitsPerSecond\": 88,
                           \"WriteUnitsPerSecond\": 77
                       }
                   }
               }
           ]" \
       --region us-east-1
   ```

1. Riceverai una risposta simile a quella seguente. Le impostazioni sul `WarmThroughput` verranno visualizzate come `ReadUnitsPerSecond` e`WriteUnitsPerSecond`. `Status` risulterà `UPDATING` quando verrà aggiornato il valore di throughput a caldo e `ACTIVE` quando sarà stato impostato il nuovo valore di throughput a caldo.

   ```
   {
       "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": "ACTIVE",
           "CreationDateTime": 1730242189.965,
           "ProvisionedThroughput": {
               "NumberOfDecreasesToday": 0,
               "ReadCapacityUnits": 20,
               "WriteCapacityUnits": 10
           },
           "TableSizeBytes": 0,
           "ItemCount": 0,
           "TableArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores",
           "TableId": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
           "GlobalSecondaryIndexes": [
               {
                   "IndexName": "GameTitleIndex",
                   "KeySchema": [
                       {
                           "AttributeName": "GameTitle",
                           "KeyType": "HASH"
                       },
                       {
                           "AttributeName": "TopScore",
                           "KeyType": "RANGE"
                       }
                   ],
                   "Projection": {
                       "ProjectionType": "INCLUDE",
                       "NonKeyAttributes": [
                           "UserId"
                       ]
                   },
                   "IndexStatus": "ACTIVE",
                   "ProvisionedThroughput": {
                       "NumberOfDecreasesToday": 0,
                       "ReadCapacityUnits": 50,
                       "WriteCapacityUnits": 25
                   },
                   "IndexSizeBytes": 0,
                   "ItemCount": 0,
                   "IndexArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores/index/GameTitleIndex",
                   "WarmThroughput": {
                       "ReadUnitsPerSecond": 50,
                       "WriteUnitsPerSecond": 25,
                       "Status": "UPDATING"
                   }
               }
           ],
           "DeletionProtectionEnabled": false,
           "WarmThroughput": {
               "ReadUnitsPerSecond": 12300,
               "WriteUnitsPerSecond": 4500,
               "Status": "UPDATING"
           }
       }
   }
   ```

## AWS SDK
<a name="warm-throughput-update-SDK"></a>

Gli esempi dell’SDK seguenti mostrano come aggiornare il valore di throughput a caldo di una tabella DynamoDB.

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

```
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.DynamoDbException;
import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexUpdate;
import software.amazon.awssdk.services.dynamodb.model.UpdateGlobalSecondaryIndexAction;
import software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest;
import software.amazon.awssdk.services.dynamodb.model.WarmThroughput;

...
public static WarmThroughput buildWarmThroughput(final Long readUnitsPerSecond,
                                                 final Long writeUnitsPerSecond) {
    return WarmThroughput.builder()
            .readUnitsPerSecond(readUnitsPerSecond)
            .writeUnitsPerSecond(writeUnitsPerSecond)
            .build();
}

public static void updateDynamoDBTable(DynamoDbClient ddb,
                                       String tableName,
                                       Long tableReadUnitsPerSecond,
                                       Long tableWriteUnitsPerSecond,
                                       String globalSecondaryIndexName,
                                       Long globalSecondaryIndexReadUnitsPerSecond,
                                       Long globalSecondaryIndexWriteUnitsPerSecond) {

    final WarmThroughput tableWarmThroughput = buildWarmThroughput(tableReadUnitsPerSecond, tableWriteUnitsPerSecond);
    final WarmThroughput gsiWarmThroughput = buildWarmThroughput(globalSecondaryIndexReadUnitsPerSecond, globalSecondaryIndexWriteUnitsPerSecond);

    final GlobalSecondaryIndexUpdate globalSecondaryIndexUpdate = GlobalSecondaryIndexUpdate.builder()
            .update(UpdateGlobalSecondaryIndexAction.builder()
                    .indexName(globalSecondaryIndexName)
                    .warmThroughput(gsiWarmThroughput)
                    .build()
            ).build();

    final UpdateTableRequest request = UpdateTableRequest.builder()
            .tableName(tableName)
            .globalSecondaryIndexUpdates(globalSecondaryIndexUpdate)
            .warmThroughput(tableWarmThroughput)
            .build();

    try {
        ddb.updateTable(request);
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    System.out.println("Done!");
}
```

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

```
from boto3 import resource
from botocore.exceptions import ClientError

def update_dynamodb_table_warm_throughput(table_name, table_read_units, table_write_units, gsi_name, gsi_read_units, gsi_write_units, region_name="us-east-1"):
    """
    Updates the warm throughput of a DynamoDB table and a global secondary index.

    :param table_name: The name of the table to update.
    :param table_read_units: The new read units per second for the table's warm throughput.
    :param table_write_units: The new write units per second for the table's warm throughput.
    :param gsi_name: The name of the global secondary index to update.
    :param gsi_read_units: The new read units per second for the GSI's warm throughput.
    :param gsi_write_units: The new write units per second for the GSI's warm throughput.
    :param region_name: The AWS Region name to target. defaults to us-east-1
    """
    try:
        ddb = resource('dynamodb', region_name)
        
        # Update the table's warm throughput
        table_warm_throughput = {
            "ReadUnitsPerSecond": table_read_units,
            "WriteUnitsPerSecond": table_write_units
        }

        # Update the global secondary index's warm throughput
        gsi_warm_throughput = {
            "ReadUnitsPerSecond": gsi_read_units,
            "WriteUnitsPerSecond": gsi_write_units
        }

        # Construct the global secondary index update
        global_secondary_index_update = [
            {
                "Update": {
                    "IndexName": gsi_name,
                    "WarmThroughput": gsi_warm_throughput
                }
            }
        ]

        # Construct the update table request
        update_table_request = {
            "TableName": table_name,
            "GlobalSecondaryIndexUpdates": global_secondary_index_update,
            "WarmThroughput": table_warm_throughput
        }

        # Update the table
        ddb.update_table(**update_table_request)
        print("Table updated successfully!")
    except ClientError as e:
        print(f"Error updating table: {e}")
        raise e
```

------
#### [ Javascript ]

```
import { DynamoDBClient, UpdateTableCommand } from "@aws-sdk/client-dynamodb";

async function updateDynamoDBTableWarmThroughput(
  tableName,
  tableReadUnits,
  tableWriteUnits,
  gsiName,
  gsiReadUnits,
  gsiWriteUnits,
  region = "us-east-1"
) {
  try {
    const ddbClient = new DynamoDBClient({ region: region });

    // Construct the update table request
    const updateTableRequest = {
      TableName: tableName,
      GlobalSecondaryIndexUpdates: [
        {
            Update: {
                IndexName: gsiName,
                WarmThroughput: {
                    ReadUnitsPerSecond: gsiReadUnits,
                    WriteUnitsPerSecond: gsiWriteUnits,
                },
            },
        },
      ],
      WarmThroughput: {
          ReadUnitsPerSecond: tableReadUnits,
          WriteUnitsPerSecond: tableWriteUnits,
      },
    };

    const command = new UpdateTableCommand(updateTableRequest);
    const response = await ddbClient.send(command);
    console.log(`Table updated successfully! Response: ${response}`);
  } catch (error) {
    console.error(`Error updating table: ${error}`);
    throw error;
  }
}
```

------

# Creazione di una nuova tabella DynamoDB con throughput caldo più elevato
<a name="create-table-warm-throughput"></a>

È possibile regolare i valori di throughput a caldo quando si crea una tabella DynamoDB attraverso la procedura seguente. Queste fasi si applicano anche alla creazione di una [tabella globale](GlobalTables.md) o di un [indice secondario](SecondaryIndexes.md).

## Console di gestione AWS
<a name="warm-throughput-create-console"></a>

Per creare una tabella DynamoDB e regolare i valori di throughput a caldo tramite la console:

1. Accedi Console di gestione AWS e apri la console DynamoDB all'indirizzo. [https://console.aws.amazon.com/dynamodb/](https://console.aws.amazon.com/dynamodb/)

1. Seleziona **Crea tabella**.

1. Seleziona un **Nome tabella**, una **Chiave di partizione** e una **Chiave di ordinamento (opzionale)**.

1. Per **Impostazioni tabella**, seleziona **Personalizza impostazioni**.

1. Nel campo **Throughput a caldo**, seleziona **Aumentare il throughput a caldo**.

1. Regola le **Unità di lettura al secondo** e le **Unità di scrittura al secondo**. Queste due impostazioni definiscono il throughput massimo che la tabella può gestire in modo istantaneo.

1. Continua ad aggiungere i dettagli rimanenti della tabella, quindi seleziona **Crea tabella**.

## AWS CLI
<a name="warm-throughput-create-CLI"></a>

L' AWS CLI esempio seguente mostra come creare una tabella DynamoDB con valori di throughput caldi personalizzati.

1. Esegui l’operazione `create-table` per creare la seguente tabella DynamoDB.

   ```
   aws dynamodb create-table \
       --table-name GameScores \
       --attribute-definitions AttributeName=UserId,AttributeType=S \
                               AttributeName=GameTitle,AttributeType=S \
                               AttributeName=TopScore,AttributeType=N  \
       --key-schema AttributeName=UserId,KeyType=HASH \
                    AttributeName=GameTitle,KeyType=RANGE \
       --provisioned-throughput ReadCapacityUnits=20,WriteCapacityUnits=10 \
       --global-secondary-indexes \
           "[
               {
                   \"IndexName\": \"GameTitleIndex\",
                   \"KeySchema\": [{\"AttributeName\":\"GameTitle\",\"KeyType\":\"HASH\"},
                                   {\"AttributeName\":\"TopScore\",\"KeyType\":\"RANGE\"}],
                   \"Projection\":{
                       \"ProjectionType\":\"INCLUDE\",
                       \"NonKeyAttributes\":[\"UserId\"]
                   },
                   \"ProvisionedThroughput\": {
                       \"ReadCapacityUnits\": 50,
                       \"WriteCapacityUnits\": 25
                   },\"WarmThroughput\": {
                       \"ReadUnitsPerSecond\": 1987,
                       \"WriteUnitsPerSecond\": 543
                   }
               }
           ]" \
       --warm-throughput ReadUnitsPerSecond=12345,WriteUnitsPerSecond=4567 \
       --region us-east-1
   ```

1. Riceverai una risposta simile a quella seguente. Le impostazioni sul `WarmThroughput` verranno visualizzate come `ReadUnitsPerSecond` e`WriteUnitsPerSecond`. `Status` risulterà `UPDATING` quando verrà aggiornato il valore di throughput a caldo e `ACTIVE` quando sarà stato impostato il nuovo valore di throughput a caldo.

   ```
   {
       "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": 1730241788.779,
           "ProvisionedThroughput": {
               "NumberOfDecreasesToday": 0,
               "ReadCapacityUnits": 20,
               "WriteCapacityUnits": 10
           },
           "TableSizeBytes": 0,
           "ItemCount": 0,
           "TableArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores",
           "TableId": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
           "GlobalSecondaryIndexes": [
               {
                   "IndexName": "GameTitleIndex",
                   "KeySchema": [
                       {
                           "AttributeName": "GameTitle",
                           "KeyType": "HASH"
                       },
                       {
                           "AttributeName": "TopScore",
                           "KeyType": "RANGE"
                       }
                   ],
                   "Projection": {
                       "ProjectionType": "INCLUDE",
                       "NonKeyAttributes": [
                           "UserId"
                       ]
                   },
                   "IndexStatus": "CREATING",
                   "ProvisionedThroughput": {
                       "NumberOfDecreasesToday": 0,
                       "ReadCapacityUnits": 50,
                       "WriteCapacityUnits": 25
                   },
                   "IndexSizeBytes": 0,
                   "ItemCount": 0,
                   "IndexArn": "arn:aws:dynamodb:us-east-1:XXXXXXXXXXXX:table/GameScores/index/GameTitleIndex",
                   "WarmThroughput": {
                       "ReadUnitsPerSecond": 1987,
                       "WriteUnitsPerSecond": 543,
                       "Status": "UPDATING"
                   }
               }
           ],
           "DeletionProtectionEnabled": false,
           "WarmThroughput": {
               "ReadUnitsPerSecond": 12345,
               "WriteUnitsPerSecond": 4567,
               "Status": "UPDATING"
           }
       }
   }
   ```

## AWS SDK
<a name="warm-throughput-create-SDK"></a>

Gli esempi dell’SDK seguenti mostrano come creare una tabella DynamoDB con valori di throughput a caldo personalizzati.

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

```
import software.amazon.awscdk.services.dynamodb.ProjectionType;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.CreateTableResponse;
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
import software.amazon.awssdk.services.dynamodb.model.KeyType;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
import software.amazon.awssdk.services.dynamodb.model.Projection;
import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
import software.amazon.awssdk.services.dynamodb.model.WarmThroughput;
...

public static WarmThroughput buildWarmThroughput(final Long readUnitsPerSecond,
                                                 final Long writeUnitsPerSecond) {
    return WarmThroughput.builder()
            .readUnitsPerSecond(readUnitsPerSecond)
            .writeUnitsPerSecond(writeUnitsPerSecond)
            .build();
}
private static AttributeDefinition buildAttributeDefinition(final String attributeName, 
                                                            final ScalarAttributeType scalarAttributeType) {
    return AttributeDefinition.builder()
            .attributeName(attributeName)
            .attributeType(scalarAttributeType)
            .build();
}
private static KeySchemaElement buildKeySchemaElement(final String attributeName, 
                                                      final KeyType keyType) {
    return KeySchemaElement.builder()
            .attributeName(attributeName)
            .keyType(keyType)
            .build();
}
public static void createDynamoDBTable(DynamoDbClient ddb,
                                       String tableName,
                                       String partitionKey,
                                       String sortKey,
                                       String miscellaneousKeyAttribute,
                                       String nonKeyAttribute,
                                       Long tableReadCapacityUnits,
                                       Long tableWriteCapacityUnits,
                                       Long tableWarmReadUnitsPerSecond,
                                       Long tableWarmWriteUnitsPerSecond,
                                       String globalSecondaryIndexName,
                                       Long globalSecondaryIndexReadCapacityUnits,
                                       Long globalSecondaryIndexWriteCapacityUnits,
                                       Long globalSecondaryIndexWarmReadUnitsPerSecond,
                                       Long globalSecondaryIndexWarmWriteUnitsPerSecond) {

    // Define the table attributes
    final AttributeDefinition partitionKeyAttribute = buildAttributeDefinition(partitionKey, ScalarAttributeType.S);
    final AttributeDefinition sortKeyAttribute = buildAttributeDefinition(sortKey, ScalarAttributeType.S);
    final AttributeDefinition miscellaneousKeyAttributeDefinition = buildAttributeDefinition(miscellaneousKeyAttribute, ScalarAttributeType.N);
    final AttributeDefinition[] attributeDefinitions = {partitionKeyAttribute, sortKeyAttribute, miscellaneousKeyAttributeDefinition};

    // Define the table key schema
    final KeySchemaElement partitionKeyElement = buildKeySchemaElement(partitionKey, KeyType.HASH);
    final KeySchemaElement sortKeyElement = buildKeySchemaElement(sortKey, KeyType.RANGE);
    final KeySchemaElement[] keySchema = {partitionKeyElement, sortKeyElement};

    // Define the provisioned throughput for the table
    final ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder()
            .readCapacityUnits(tableReadCapacityUnits)
            .writeCapacityUnits(tableWriteCapacityUnits)
            .build();

    // Define the Global Secondary Index (GSI)
    final KeySchemaElement globalSecondaryIndexPartitionKeyElement = buildKeySchemaElement(sortKey, KeyType.HASH);
    final KeySchemaElement globalSecondaryIndexSortKeyElement = buildKeySchemaElement(miscellaneousKeyAttribute, KeyType.RANGE);
    final KeySchemaElement[] gsiKeySchema = {globalSecondaryIndexPartitionKeyElement, globalSecondaryIndexSortKeyElement};

    final Projection gsiProjection = Projection.builder()
            .projectionType(String.valueOf(ProjectionType.INCLUDE))
            .nonKeyAttributes(nonKeyAttribute)
            .build();
    final ProvisionedThroughput gsiProvisionedThroughput = ProvisionedThroughput.builder()
            .readCapacityUnits(globalSecondaryIndexReadCapacityUnits)
            .writeCapacityUnits(globalSecondaryIndexWriteCapacityUnits)
            .build();
    // Define the warm throughput for the Global Secondary Index (GSI)
    final WarmThroughput gsiWarmThroughput = buildWarmThroughput(globalSecondaryIndexWarmReadUnitsPerSecond, globalSecondaryIndexWarmWriteUnitsPerSecond);
    final GlobalSecondaryIndex globalSecondaryIndex = GlobalSecondaryIndex.builder()
            .indexName(globalSecondaryIndexName)
            .keySchema(gsiKeySchema)
            .projection(gsiProjection)
            .provisionedThroughput(gsiProvisionedThroughput)
            .warmThroughput(gsiWarmThroughput)
            .build();

    // Define the warm throughput for the table
    final WarmThroughput tableWarmThroughput = buildWarmThroughput(tableWarmReadUnitsPerSecond, tableWarmWriteUnitsPerSecond);

    final CreateTableRequest request = CreateTableRequest.builder()
            .tableName(tableName)
            .attributeDefinitions(attributeDefinitions)
            .keySchema(keySchema)
            .provisionedThroughput(provisionedThroughput)
            .globalSecondaryIndexes(globalSecondaryIndex)
            .warmThroughput(tableWarmThroughput)
            .build();

    CreateTableResponse response = ddb.createTable(request);
    System.out.println(response);
}
```

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

```
from boto3 import resource
from botocore.exceptions import ClientError

def create_dynamodb_table_warm_throughput(table_name, partition_key, sort_key, misc_key_attr, non_key_attr, table_provisioned_read_units, table_provisioned_write_units, table_warm_reads, table_warm_writes, gsi_name, gsi_provisioned_read_units, gsi_provisioned_write_units, gsi_warm_reads, gsi_warm_writes, region_name="us-east-1"):
    """
    Creates a DynamoDB table with a warm throughput setting configured.

    :param table_name: The name of the table to be created.
    :param partition_key: The partition key for the table being created.
    :param sort_key: The sort key for the table being created.
    :param misc_key_attr: A miscellaneous key attribute for the table being created.
    :param non_key_attr: A non-key attribute for the table being created.
    :param table_provisioned_read_units: The newly created table's provisioned read capacity units.
    :param table_provisioned_write_units: The newly created table's provisioned write capacity units.
    :param table_warm_reads: The read units per second setting for the table's warm throughput.
    :param table_warm_writes: The write units per second setting for the table's warm throughput.
    :param gsi_name: The name of the Global Secondary Index (GSI) to be created on the table.
    :param gsi_provisioned_read_units: The configured Global Secondary Index (GSI) provisioned read capacity units.
    :param gsi_provisioned_write_units: The configured Global Secondary Index (GSI) provisioned write capacity units.
    :param gsi_warm_reads: The read units per second setting for the Global Secondary Index (GSI)'s warm throughput.
    :param gsi_warm_writes: The write units per second setting for the Global Secondary Index (GSI)'s warm throughput.
    :param region_name: The AWS Region name to target. defaults to us-east-1
    """
    try:
        ddb = resource('dynamodb', region_name)
        
        # Define the table attributes
        attribute_definitions = [
            { "AttributeName": partition_key, "AttributeType": "S" },
            { "AttributeName": sort_key, "AttributeType": "S" },
            { "AttributeName": misc_key_attr, "AttributeType": "N" }
        ]
        
        # Define the table key schema
        key_schema = [
            { "AttributeName": partition_key, "KeyType": "HASH" },
            { "AttributeName": sort_key, "KeyType": "RANGE" }
        ]
        
        # Define the provisioned throughput for the table
        provisioned_throughput = {
            "ReadCapacityUnits": table_provisioned_read_units,
            "WriteCapacityUnits": table_provisioned_write_units
        }
        
        # Define the global secondary index
        gsi_key_schema = [
            { "AttributeName": sort_key, "KeyType": "HASH" },
            { "AttributeName": misc_key_attr, "KeyType": "RANGE" }
        ]
        gsi_projection = {
            "ProjectionType": "INCLUDE",
            "NonKeyAttributes": [non_key_attr]
        }
        gsi_provisioned_throughput = {
            "ReadCapacityUnits": gsi_provisioned_read_units,
            "WriteCapacityUnits": gsi_provisioned_write_units
        }
        gsi_warm_throughput = {
            "ReadUnitsPerSecond": gsi_warm_reads,
            "WriteUnitsPerSecond": gsi_warm_writes
        }
        global_secondary_indexes = [
            {
                "IndexName": gsi_name,
                "KeySchema": gsi_key_schema,
                "Projection": gsi_projection,
                "ProvisionedThroughput": gsi_provisioned_throughput,
                "WarmThroughput": gsi_warm_throughput
            }
        ]
        
        # Define the warm throughput for the table
        warm_throughput = {
            "ReadUnitsPerSecond": table_warm_reads,
            "WriteUnitsPerSecond": table_warm_writes
        }
        
        # Create the DynamoDB client and create the table
        response = ddb.create_table(
            TableName=table_name,
            AttributeDefinitions=attribute_definitions,
            KeySchema=key_schema,
            ProvisionedThroughput=provisioned_throughput,
            GlobalSecondaryIndexes=global_secondary_indexes,
            WarmThroughput=warm_throughput
        )
        
        print(response)
    except ClientError as e:
        print(f"Error creating table: {e}")
        raise e
```

------
#### [ Javascript ]

```
import { DynamoDBClient, CreateTableCommand } from "@aws-sdk/client-dynamodb";

async function createDynamoDBTableWithWarmThroughput(
  tableName,
  partitionKey,
  sortKey,
  miscKeyAttr,
  nonKeyAttr,
  tableProvisionedReadUnits,
  tableProvisionedWriteUnits,
  tableWarmReads,
  tableWarmWrites,
  indexName,
  indexProvisionedReadUnits,
  indexProvisionedWriteUnits,
  indexWarmReads,
  indexWarmWrites,
  region = "us-east-1"
) {
  try {
    const ddbClient = new DynamoDBClient({ region: region });
    const command = new CreateTableCommand({
      TableName: tableName,
      AttributeDefinitions: [
          { AttributeName: partitionKey, AttributeType: "S" },
          { AttributeName: sortKey, AttributeType: "S" },
          { AttributeName: miscKeyAttr, AttributeType: "N" },
      ],
      KeySchema: [
          { AttributeName: partitionKey, KeyType: "HASH" },
          { AttributeName: sortKey, KeyType: "RANGE" },
      ],
      ProvisionedThroughput: {
          ReadCapacityUnits: tableProvisionedReadUnits,
          WriteCapacityUnits: tableProvisionedWriteUnits,
      },
      WarmThroughput: {
          ReadUnitsPerSecond: tableWarmReads,
          WriteUnitsPerSecond: tableWarmWrites,
      },
      GlobalSecondaryIndexes: [
          {
            IndexName: indexName,
            KeySchema: [
                { AttributeName: sortKey, KeyType: "HASH" },
                { AttributeName: miscKeyAttr, KeyType: "RANGE" },
            ],
            Projection: {
                ProjectionType: "INCLUDE",
                NonKeyAttributes: [nonKeyAttr],
            },
            ProvisionedThroughput: {
                ReadCapacityUnits: indexProvisionedReadUnits,
                WriteCapacityUnits: indexProvisionedWriteUnits,
            },
            WarmThroughput: {
                ReadUnitsPerSecond: indexWarmReads,
                WriteUnitsPerSecond: indexWarmWrites,
            },
          },
      ],
    });
    const response = await ddbClient.send(command);
    console.log(response);
  } catch (error) {
    console.error(`Error creating table: ${error}`);
    throw error;
  }
}
```

------

# Funzionamento del throughput a caldo di DynamoDB in diversi scenari
<a name="warm-throughput-scenarios"></a>

Di seguito sono riportati alcuni scenari diversi che possono verificarsi durante l’utilizzo del throughput a caldo di DynamoDB.

**Topics**
+ [Throughput a caldo e modelli di accesso irregolari](#warm-throughput-scenarios-uneven)
+ [Throughput a caldo per una tabella con provisioning](#warm-throughput-scenarios-provisioned)
+ [Throughput a caldo per una tabella on demand](#warm-throughput-scenarios-ondemand)
+ [Throughput a caldo per una tabella on demand con un throughput massimo configurato](#warm-throughput-scenarios-max)

## Throughput a caldo e modelli di accesso irregolari
<a name="warm-throughput-scenarios-uneven"></a>

Una tabella può avere un throughput di 30.000 unità di lettura al secondo e 10.000 unità di scrittura al secondo, ma è comunque possibile che si verifichi una limitazione (della larghezza di banda della rete) delle operazioni di lettura o scrittura prima di raggiungere tali valori. Ciò è probabilmente dovuto a una partizione calda. Sebbene DynamoDB possa continuare a scalare per supportare un throughput praticamente illimitato, ogni singola partizione è limitata a 1.000 unità di scrittura al secondo e 3.000 unità di lettura al secondo. Se l’applicazione indirizza troppo traffico verso una piccola parte delle partizioni della tabella, la limitazione (della larghezza di banda della rete) può verificarsi anche prima di raggiungere i valori di throughput a caldo della tabella. Si consiglia di seguire le [best practice di DynamoDB](bp-partition-key-design.md) per garantire una scalabilità perfetta ed evitare partizioni calde.

## Throughput a caldo per una tabella con provisioning
<a name="warm-throughput-scenarios-provisioned"></a>

Si prenda in considerazione una tabella con provisioning con un throughput a caldo di 30.000 unità di lettura al secondo e 10.000 unità di scrittura al secondo, ma che attualmente ha un throughput allocato di 4.000 RCU e 8.000 WCU. È possibile scalare istantaneamente il throughput allocato alla tabella fino a 30.000 RCU o 10.000 WCU aggiornando le impostazioni di throughput allocato. Quando si aumenta il throughput allocato oltre questi valori, il throughput a caldo si adeguerà automaticamente ai nuovi valori più alti, poiché è stato impostato un nuovo throughput di picco. Ad esempio, se si imposta il throughput allocato su 50.000 RCU, il throughput a caldo aumenterà a 50.000 unità di lettura al secondo.

```
"ProvisionedThroughput": 
    {
        "ReadCapacityUnits": 4000,
        "WriteCapacityUnits": 8000 
    }
"WarmThroughput": 
    { 
        "ReadUnitsPerSecond": 30000,
        "WriteUnitsPerSecond": 10000
    }
```

## Throughput a caldo per una tabella on demand
<a name="warm-throughput-scenarios-ondemand"></a>

Una nuova tabella on demand inizia con un throughput a caldo di 12.000 unità di lettura al secondo e 4.000 unità di scrittura al secondo. La tabella può supportare in modo istantaneo un traffico sostenuto fino a questi livelli. Quando le richieste superano le 12.000 unità di lettura al secondo o le 4.000 unità di scrittura al secondo, il throughput a caldo si adeguerà automaticamente a valori più alti.

```
"WarmThroughput": 
    { 
        "ReadUnitsPerSecond": 12000,
        "WriteUnitsPerSecond": 4000
    }
```

## Throughput a caldo per una tabella on demand con un throughput massimo configurato
<a name="warm-throughput-scenarios-max"></a>

Si prenda in considerazione una tabella on demand con una throughput a caldo di 30.000 unità di lettura al secondo, ma con un [throughput massimo](on-demand-capacity-mode-max-throughput.md) configurato a 5.000 unità di richiesta di lettura (RRU). In questo scenario, il throughput della tabella sarà limitato al massimo di 5.000 RRU impostate. Tutte le richieste di throughput che superano questo limite subiranno una limitazione (della larghezza di banda della rete). Tuttavia, è possibile modificare il throughput massimo specifico della tabella in qualsiasi momento in base alle esigenze dell’applicazione.

```
"OnDemandThroughput": 
    {
        "MaxReadRequestUnits": 5000,
        "MaxWriteRequestUnits": 4000
    }
"WarmThroughput": 
    { 
        "ReadUnitsPerSecond": 30000,
        "WriteUnitsPerSecond": 10000
    }
```