2

I'm trying to update items on my Users table. emailis my HASH key and id my RANGE

{
  "accessToken": {
    "M": {
      "expirationDate": {
        "N": "1622715427"
      },
      "token": {
        "S": "dummy-auth-accessToken-xxx"
      }
    }
  },
  "email": {
    "S": "[email protected]"
  },
  "firstName": {
    "S": "Xxx"
  },
  "id": {
    "S": "2"
  },
  "lastName": {
    "S": "Yyyy"
  },
  "password": {
    "S": "tataToto"
  },
  "refreshToken": {
    "M": {
      "expirationDate": {
        "N": "1622715427"
      },
      "token": {
        "S": "dummy-auth-refreshToken-xxx"
      }
    }
  },
  "username": {
    "S": "XxxY"
  }
}

I would like to update access and refresh token, so i'm doing this:

const dynamoDb = new AWS.DynamoDB.DocumentClient();

const params = {
          TableName: 'Users',
          Key: { email: '[email protected]' },
          UpdateExpression: 'set #at1 = :1, #at2 = :2, #at3 = :3, #at4 = :4',
          ExpressionAttributeNames: {
            '#at1': 'accessToken.token',
            '#at2': 'refreshToken.token',
            '#at3': 'accessToken.expirationDate',
            '#at4': 'refreshToken.expirationDate'
          },
          ExpressionAttributeValues: {
            ':1': 'new-dummy-auth-accessToken',
            ':2': 'new-dummy-auth-refreshToken',
            ':3': 1234567,
            ':4': 123456787654
          },
          ReturnValues: 'UPDATED_NEW'
        }

dynamoDb.update(params, (err, data) => {})

but i got:

Unable to update item. Error JSON: {
  "message": "The provided key element does not match the schema",
  "code": "ValidationException",
  "time": "2020-06-03T11:37:57.931Z",
  "requestId": "PDTS2SDOEIOPMAO4VHGU6QM21JVV4KQNSO5AEMVJF66Q9ASUAAJG",
  "statusCode": 400,
  "retryable": false,
  "retryDelay": 27.556977097280456
}

What I'm doing wrong please?

1
  • Your DynamoDB table has a composite key (email + id). To identify a single item, you need to supply both. You've only supplied the email in your key. Commented Jun 3, 2020 at 12:11

1 Answer 1

2

It's my bad... Need to add HASH AND RANGE key on params object

Key: { 
  id: "2"
  email: '[email protected]'
}

and my expressions is not good but i know how fix it :)

Ty to read x)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.