Jump to Content

New API Documentation - Developer Preview Available

We are excited to announce the developer preview of our new API documentation for AWS SDK for JavaScript v3. Please follow instructions on the landing page to leave us your feedback.

Class GetItemCommandProtected

The GetItem operation returns a set of attributes for the item with the given primary key. If there is no matching item, GetItem does not return any data and there will be no Item element in the response.

GetItem provides an eventually consistent read by default. If your application requires a strongly consistent read, set ConsistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value.

Example

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

import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb"; // ES Modules import
// const { DynamoDBClient, GetItemCommand } = require("@aws-sdk/client-dynamodb"); // CommonJS import
const client = new DynamoDBClient(config);
const input = { // GetItemInput
TableName: "STRING_VALUE", // required
Key: { // Key // required
"<keys>": { // AttributeValue Union: only one key present
S: "STRING_VALUE",
N: "STRING_VALUE",
B: "BLOB_VALUE",
SS: [ // StringSetAttributeValue
"STRING_VALUE",
],
NS: [ // NumberSetAttributeValue
"STRING_VALUE",
],
BS: [ // BinarySetAttributeValue
"BLOB_VALUE",
],
M: { // MapAttributeValue
"<keys>": {// Union: only one key present
S: "STRING_VALUE",
N: "STRING_VALUE",
B: "BLOB_VALUE",
SS: [
"STRING_VALUE",
],
NS: [
"STRING_VALUE",
],
BS: [
"BLOB_VALUE",
],
M: {
"<keys>": "<AttributeValue>",
},
L: [ // ListAttributeValue
"<AttributeValue>",
],
NULL: true || false,
BOOL: true || false,
},
},
L: [
"<AttributeValue>",
],
NULL: true || false,
BOOL: true || false,
},
},
AttributesToGet: [ // AttributeNameList
"STRING_VALUE",
],
ConsistentRead: true || false,
ReturnConsumedCapacity: "INDEXES" || "TOTAL" || "NONE",
ProjectionExpression: "STRING_VALUE",
ExpressionAttributeNames: { // ExpressionAttributeNameMap
"<keys>": "STRING_VALUE",
},
};
const command = new GetItemCommand(input);
const response = await client.send(command);
// { // GetItemOutput
// Item: { // AttributeMap
// "<keys>": { // AttributeValue Union: only one key present
// S: "STRING_VALUE",
// N: "STRING_VALUE",
// B: "BLOB_VALUE",
// SS: [ // StringSetAttributeValue
// "STRING_VALUE",
// ],
// NS: [ // NumberSetAttributeValue
// "STRING_VALUE",
// ],
// BS: [ // BinarySetAttributeValue
// "BLOB_VALUE",
// ],
// M: { // MapAttributeValue
// "<keys>": {// Union: only one key present
// S: "STRING_VALUE",
// N: "STRING_VALUE",
// B: "BLOB_VALUE",
// SS: [
// "STRING_VALUE",
// ],
// NS: [
// "STRING_VALUE",
// ],
// BS: [
// "BLOB_VALUE",
// ],
// M: {
// "<keys>": "<AttributeValue>",
// },
// L: [ // ListAttributeValue
// "<AttributeValue>",
// ],
// NULL: true || false,
// BOOL: true || false,
// },
// },
// L: [
// "<AttributeValue>",
// ],
// NULL: true || false,
// BOOL: true || false,
// },
// },
// 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"),
// },
// },
// },
// };

Param

GetItemCommandInput

Returns

GetItemCommandOutput

See

Throws

InternalServerError (server fault)

An error occurred on the server side.

Throws

InvalidEndpointException (client fault)

Throws

ProvisionedThroughputExceededException (client fault)

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.

Throws

RequestLimitExceeded (client fault)

Throughput exceeds the current throughput quota for your account. Please contact Amazon Web Services Support to request a quota increase.

Throws

ResourceNotFoundException (client fault)

The operation tried to access a nonexistent table or index. The resource might not be specified correctly, or its status might not be ACTIVE.

Throws

DynamoDBServiceException

Base exception class for all service exceptions from DynamoDB service.

Example

To read an item from a table

// This example retrieves an item from the Music table. The table has a partition key and a sort key (Artist and SongTitle), so you must specify both of these attributes.
const input = {
"Key": {
"Artist": {
"S": "Acme Band"
},
"SongTitle": {
"S": "Happy Day"
}
},
"TableName": "Music"
};
const command = new GetItemCommand(input);
const response = await client.send(command);
/* response ==
{
"Item": {
"AlbumTitle": {
"S": "Songs About Life"
},
"Artist": {
"S": "Acme Band"
},
"SongTitle": {
"S": "Happy Day"
}
}
}
*/
// example id: to-read-an-item-from-a-table-1475884258350

Hierarchy

Constructors

Properties

middlewareStack: MiddlewareStack<GetItemCommandInput, GetItemCommandOutput>

Methods