15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DynamoDBで予約語を使う時は置換しないと怒られる

Posted at

概要

Node.jsでDynamoDBからscanしようとしたら、予約語を使っていたため怒られた

間違った例

var dynamodb = AWS.DynamoDB();
var params = {
  TableName                : "a_table",
  ProjectionExpression     : "DateTime,Attr1,Attr2",
};
dynamodb.scan(params, function(err, data) {
  if (err) return console.log(err, err.stack);
  console.log(data.Items);
});
ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword; reserved keyword: DateTime

正しい例

var dynamodb = AWS.DynamoDB();
var params = {
  TableName                : "a_table",
  ProjectionExpression     : "#dt,Attr1,Attr2",
  ExpressionAttributeNames : {
    "#dt"  : ATTR_DATE_TIME,
  },
};
dynamodb.scan(params, function(err, data) {
  if (err) return console.log(err, err.stack);
  console.log(data.Items);
});
15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?