DynamoDB — cannot specify projection when Select is COUNT

TL;DR — Your Query/Scan set Select: COUNT and a ProjectionExpression (or the legacy AttributesToGet). COUNT returns only the number of matching items, never the items themselves, so naming attributes to return is contradictory — DynamoDB rejects it. Pick one: Select: COUNT with no projection, or a projection with Select: SPECIFIC_ATTRIBUTES (the default when you supply a ProjectionExpression).

What it means

ValidationException: Cannot specify the AttributesToGet when choosing to get only the Count
ValidationException: Cannot use ProjectionExpression when Select is COUNT

Select controls what a read returns. COUNT asks DynamoDB for a tally (Count/ScannedCount) and no item data. A ProjectionExpression/AttributesToGet asks for specific attributes of returned items. Those two are mutually exclusive — you can't count items and also project their attributes in the same call.

Why it happens

  • Both parameters set at onceSelect: COUNT left in place while a ProjectionExpression was added (or vice versa).
  • Legacy AttributesToGet combined with Select: COUNT.
  • A query builder that always attaches a projection, even when the caller only wanted a count.
  • Misunderstanding Select — expecting COUNT to also hand back the items it counted.

How to fix it

  1. Just counting? Drop the projection. Set Select: COUNT and remove ProjectionExpression/AttributesToGet.
  2. Need specific attributes? Drop Select: COUNT. Supply a ProjectionExpression; DynamoDB defaults Select to SPECIFIC_ATTRIBUTES, so you usually don't set Select at all.
  3. Need both the count and the items? Make one call for the items (with your projection) and read its Count, or make a separate Select: COUNT call.
  4. Prefer ProjectionExpression over AttributesToGet — the legacy parameter is discouraged and only works with Select: SPECIFIC_ATTRIBUTES.

Just want a quick count or a projected view while exploring? The DynoTable desktop app runs queries and shows the matched count without you hand-assembling conflicting Select parameters.

不必透過主控台就能操作 DynamoDB

DynoTable 是一款快速的 DynamoDB 桌面用戶端 — 瀏覽表格、執行 SQL 風格的查詢,並在本機編輯項目。