ProjectionExpression causes 'Unsupported type passed' error when querying

0

Hello,

I seem to be having a strange issue when querying on my GSI that as soon as I specify the fields I wish to return in the query, I get the "Unsupported type passed" error.

Here's the query:

{
  TableName: 'RatingsTable',
  IndexName: 'username',
  KeyConditionExpression: '#username = :username',
  ExpressionAttributeNames: { '#username': 'username' },
  ExpressionAttributeValues: { ':username': { S: 'jonathanmsifleet' } },
  ProjectionExpression: 'username, imdb_title_id'
}

The table:

RatingsTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: RatingsTable
    BillingMode: PAY_PER_REQUEST
    AttributeDefinitions:
      - AttributeName: imdb_title_id
        AttributeType: N
      - AttributeName: username
        AttributeType: S

    KeySchema:
      - AttributeName: imdb_title_id
        KeyType: HASH
      - AttributeName: username
        KeyType: RANGE

    GlobalSecondaryIndexes:
      - IndexName: username
        KeySchema:
          - AttributeName: username
            KeyType: HASH
        Projection:
          ProjectionType: ALL

The strange thing is that if I remove ProjectionExpression from the query it executes fine, yet as soon as I specify fields then it throws the error. The error in its entirety in Cloudwatch is Unsupported type passed: username, if I remove username then it moves to the next field, Unsupported type passed: imdb_title_id.

Here's the code I am using to run the query:

    query = {
      TableName: 'RatingsTable',
      IndexName: 'username',
      KeyConditionExpression: '#username = :username',
      ExpressionAttributeNames: {
        '#username': 'username'
      },
      ExpressionAttributeValues: {
        ':username': { S: username }
      },
      ProjectionExpression: 'username, imdb_title_id'
    };
    console.log('query', query);

    const result = await dbClient.send(new QueryCommand(query));

Any ideas what I am doing wrong?

질문됨 2년 전1764회 조회
1개 답변
1

I would start by ensuring you are on the latest AWS SDK version for node V3. It works for me on v3.44.0 with no issue, only thing I needed to change was your ExpressionAttributeValues as V3 takes native string and no DDB JSON.

    query = {
      TableName: 'RatingsTable',
      IndexName: 'username',
      KeyConditionExpression: '#username = :username',
      ExpressionAttributeNames: {
        '#username': 'username'
      },
      ExpressionAttributeValues: {
        ':username':  username
      },
      ProjectionExpression: 'username, imdb_title_id'
    };
    console.log('query', query);

    const result = await dbClient.send(new QueryCommand(query));
profile pictureAWS
전문가
답변함 2년 전
  • Without specifying the Data type for ExpressionAttributeValues, TypeScript throws this error: Type 'string' is not assignable to type 'AttributeValue' and CloudWatch gives this error, Cannot read property '0' of undefined. I'll try downgrading to 3.44 as I'm using 3.54.1

    Edit: Downgrading and Specifying Data type solved this!

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠