- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
ExecuteTransactionCommand
This operation allows you to perform transactional reads or writes on data stored in DynamoDB, using PartiQL.
The entire transaction must consist of either read statements or write statements, you cannot mix both in one transaction. The EXISTS function is an exception and can be used to check the condition of specific attributes of the item in a similar manner to ConditionCheck
in the TransactWriteItems API.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { DynamoDBClient, ExecuteTransactionCommand } from "@aws-sdk/client-dynamodb"; // ES Modules import
// const { DynamoDBClient, ExecuteTransactionCommand } = require("@aws-sdk/client-dynamodb"); // CommonJS import
const client = new DynamoDBClient(config);
const input = { // ExecuteTransactionInput
TransactStatements: [ // ParameterizedStatements // required
{ // ParameterizedStatement
Statement: "STRING_VALUE", // required
Parameters: [ // PreparedStatementParameters
{ // AttributeValue Union: only one key present
S: "STRING_VALUE",
N: "STRING_VALUE",
B: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
SS: [ // StringSetAttributeValue
"STRING_VALUE",
],
NS: [ // NumberSetAttributeValue
"STRING_VALUE",
],
BS: [ // BinarySetAttributeValue
new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
],
M: { // MapAttributeValue
"<keys>": {// Union: only one key present
S: "STRING_VALUE",
N: "STRING_VALUE",
B: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
SS: [
"STRING_VALUE",
],
NS: [
"STRING_VALUE",
],
BS: [
new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
],
M: {
"<keys>": "<AttributeValue>",
},
L: [ // ListAttributeValue
"<AttributeValue>",
],
NULL: true || false,
BOOL: true || false,
},
},
L: [
"<AttributeValue>",
],
NULL: true || false,
BOOL: true || false,
},
],
ReturnValuesOnConditionCheckFailure: "ALL_OLD" || "NONE",
},
],
ClientRequestToken: "STRING_VALUE",
ReturnConsumedCapacity: "INDEXES" || "TOTAL" || "NONE",
};
const command = new ExecuteTransactionCommand(input);
const response = await client.send(command);
// { // ExecuteTransactionOutput
// Responses: [ // ItemResponseList
// { // ItemResponse
// Item: { // AttributeMap
// "<keys>": { // AttributeValue Union: only one key present
// S: "STRING_VALUE",
// N: "STRING_VALUE",
// B: new Uint8Array(),
// SS: [ // StringSetAttributeValue
// "STRING_VALUE",
// ],
// NS: [ // NumberSetAttributeValue
// "STRING_VALUE",
// ],
// BS: [ // BinarySetAttributeValue
// new Uint8Array(),
// ],
// M: { // MapAttributeValue
// "<keys>": {// Union: only one key present
// S: "STRING_VALUE",
// N: "STRING_VALUE",
// B: new Uint8Array(),
// SS: [
// "STRING_VALUE",
// ],
// NS: [
// "STRING_VALUE",
// ],
// BS: [
// new Uint8Array(),
// ],
// M: {
// "<keys>": "<AttributeValue>",
// },
// L: [ // ListAttributeValue
// "<AttributeValue>",
// ],
// NULL: true || false,
// BOOL: true || false,
// },
// },
// L: [
// "<AttributeValue>",
// ],
// NULL: true || false,
// BOOL: true || false,
// },
// },
// },
// ],
// ConsumedCapacity: [ // ConsumedCapacityMultiple
// { // ConsumedCapacity
// TableName: "STRING_VALUE",
// CapacityUnits: Number("double"),
// ReadCapacityUnits: Number("double"),
// WriteCapacityUnits: Number("double"),
// Table: { // Capacity
// ReadCapacityUnits: Number("double"),
// WriteCapacityUnits: Number("double"),
// CapacityUnits: Number("double"),
// },
// LocalSecondaryIndexes: { // SecondaryIndexesCapacityMap
// "<keys>": {
// ReadCapacityUnits: Number("double"),
// WriteCapacityUnits: Number("double"),
// CapacityUnits: Number("double"),
// },
// },
// GlobalSecondaryIndexes: {
// "<keys>": {
// ReadCapacityUnits: Number("double"),
// WriteCapacityUnits: Number("double"),
// CapacityUnits: Number("double"),
// },
// },
// },
// ],
// };
ExecuteTransactionCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
TransactStatements Required | ParameterizedStatement[] | undefined | The list of PartiQL statements representing the transaction to run. |
ClientRequestToken | string | undefined | Set this value to get remaining results, if |
ReturnConsumedCapacity | ReturnConsumedCapacity | undefined | Determines the level of detail about either provisioned or on-demand throughput consumption that is returned in the response. For more information, see TransactGetItems and TransactWriteItems . |
ExecuteTransactionCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
ConsumedCapacity | ConsumedCapacity[] | undefined | The capacity units consumed by the entire operation. The values of the list are ordered according to the ordering of the statements. |
Responses | ItemResponse[] | undefined | The response to a PartiQL transaction. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
IdempotentParameterMismatchException | client | DynamoDB rejected the request because you retried a request with a different payload but with an idempotent token that was already used. |
InternalServerError | server | An error occurred on the server side. |
ProvisionedThroughputExceededException | client | Your request rate is too high. The Amazon Web Services SDKs for DynamoDB automatically retry requests that receive this exception. Your request is eventually successful, unless your retry queue is too large to finish. Reduce the frequency of requests and use exponential backoff. For more information, go to Error Retries and Exponential Backoff in the Amazon DynamoDB Developer Guide. |
RequestLimitExceeded | client | Throughput exceeds the current throughput quota for your account. Please contact Amazon Web ServicesSupport to request a quota increase. |
ResourceNotFoundException | client | The operation tried to access a nonexistent table or index. The resource might not be specified correctly, or its status might not be |
TransactionCanceledException | client | The entire transaction request was canceled. DynamoDB cancels a
DynamoDB cancels a
If using Java, DynamoDB lists the cancellation reasons on the Cancellation reason codes and possible error messages:
|
TransactionInProgressException | client | The transaction with the given request token is already in progress. Recommended Settings This is a general recommendation for handling the
Assuming default retry policy , example timeout settings based on the guidelines above are as follows: Example timeline:
|
DynamoDBServiceException | Base exception class for all service exceptions from DynamoDB service. |