ExecuteStatementCommand

This operation allows you to perform reads and singleton writes on data stored in DynamoDB, using PartiQL.

For PartiQL reads (SELECT statement), if the total number of processed items exceeds the maximum dataset size limit of 1 MB, the read stops and results are returned to the user as a LastEvaluatedKey value to continue the read in a subsequent operation. If the filter criteria in WHERE clause does not match any data, the read will return an empty result set.

A single SELECT statement response can return up to the maximum number of items (if using the Limit parameter) or a maximum of 1 MB of data (and then apply any filtering to the results using WHERE clause). If LastEvaluatedKey is present in the response, you need to paginate the result set. If NextToken is present, you need to paginate the result set and include NextToken.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { DynamoDBClient, ExecuteStatementCommand } from "@aws-sdk/client-dynamodb"; // ES Modules import
// const { DynamoDBClient, ExecuteStatementCommand } = require("@aws-sdk/client-dynamodb"); // CommonJS import
const client = new DynamoDBClient(config);
const input = { // ExecuteStatementInput
  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,
    },
  ],
  ConsistentRead: true || false,
  NextToken: "STRING_VALUE",
  ReturnConsumedCapacity: "INDEXES" || "TOTAL" || "NONE",
  Limit: Number("int"),
  ReturnValuesOnConditionCheckFailure: "ALL_OLD" || "NONE",
};
const command = new ExecuteStatementCommand(input);
const response = await client.send(command);
// { // ExecuteStatementOutput
//   Items: [ // ItemList
//     { // 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,
//       },
//     },
//   ],
//   NextToken: "STRING_VALUE",
//   ConsumedCapacity: { // 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"),
//       },
//     },
//   },
//   LastEvaluatedKey: { // Key
//     "<keys>": "<AttributeValue>",
//   },
// };

ExecuteStatementCommand Input

See ExecuteStatementCommandInput for more details

Parameter
Type
Description
Statement
Required
string | undefined

The PartiQL statement representing the operation to run.

ConsistentRead
boolean | undefined

The consistency of a read operation. If set to true, then a strongly consistent read is used; otherwise, an eventually consistent read is used.

Limit
number | undefined

The maximum number of items to evaluate (not necessarily the number of matching items). If DynamoDB processes the number of items up to the limit while processing the results, it stops the operation and returns the matching values up to that point, along with a key in LastEvaluatedKey to apply in a subsequent operation so you can pick up where you left off. Also, if the processed dataset size exceeds 1 MB before DynamoDB reaches this limit, it stops the operation and returns the matching values up to the limit, and a key in LastEvaluatedKey to apply in a subsequent operation to continue the operation.

NextToken
string | undefined

Set this value to get remaining results, if NextToken was returned in the statement response.

Parameters
AttributeValue[] | undefined

The parameters for the PartiQL statement, if any.

ReturnConsumedCapacity
ReturnConsumedCapacity | undefined

Determines the level of detail about either provisioned or on-demand throughput consumption that is returned in the response:

  • INDEXES - The response includes the aggregate ConsumedCapacity for the operation, together with ConsumedCapacity for each table and secondary index that was accessed.

    Note that some operations, such as GetItem and BatchGetItem, do not access any indexes at all. In these cases, specifying INDEXES will only return ConsumedCapacity information for table(s).

  • TOTAL - The response includes only the aggregate ConsumedCapacity for the operation.

  • NONE - No ConsumedCapacity details are included in the response.

ReturnValuesOnConditionCheckFailure
ReturnValuesOnConditionCheckFailure | undefined

An optional parameter that returns the item attributes for an ExecuteStatement operation that failed a condition check.

There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No read capacity units are consumed.

ExecuteStatementCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
ConsumedCapacity
ConsumedCapacity | undefined

The capacity units consumed by an operation. The data returned includes the total provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation. ConsumedCapacity is only returned if the request asked for it. For more information, see Provisioned capacity mode  in the Amazon DynamoDB Developer Guide.

Items
Record<string, AttributeValue>[] | undefined

If a read operation was used, this property will contain the result of the read operation; a map of attribute names and their values. For the write operations this value will be empty.

LastEvaluatedKey
Record<string, AttributeValue> | undefined

The primary key of the item where the operation stopped, inclusive of the previous result set. Use this value to start a new operation, excluding this value in the new request. If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved. If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set. The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty.

NextToken
string | undefined

If the response of a read request exceeds the response payload limit DynamoDB will set this value in the response. If set, you can use that this value in the subsequent request to get the remaining results.

Throws

Name
Fault
Details
ConditionalCheckFailedException
client

A condition specified in the operation failed to be evaluated.

DuplicateItemException
client

There was an attempt to insert an item with the same primary key as an item that already exists in the DynamoDB table.

InternalServerError
server

An error occurred on the server side.

ItemCollectionSizeLimitExceededException
client

An item collection is too large. This exception is only returned for tables that have one or more local secondary indexes.

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 ACTIVE.

TransactionConflictException
client

Operation was rejected because there is an ongoing transaction for the item.

DynamoDBServiceException
Base exception class for all service exceptions from DynamoDB service.