- 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.
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
Parameter | Type | Description |
---|
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 |
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 |
NextToken | string | undefined | Set this value to get remaining results, if |
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:
|
ReturnValuesOnConditionCheckFailure | ReturnValuesOnConditionCheckFailure | undefined | An optional parameter that returns the item attributes for an 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 |
---|
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. |
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 |
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 |
---|
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 |
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. |