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: 1 validation error detected: Cannot specify the AttributesToGet when choosing to get only the Count
# what the engine actually returns, reproduced against DynamoDB Local:
ValidationException: 1 validation error detected: Cannot specify the ProjectionExpression when choosing to get only the Count(That's the message with the legacy AttributesToGet parameter; with ProjectionExpression the wording differs, but the rule is the same.) 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 — the Query API reference spells it out: "If you use the ProjectionExpression parameter, then the value for Select can only be SPECIFIC_ATTRIBUTES. Any other value for Select will return an error." One cost note: COUNT still consumes the same read capacity as actually fetching the items — it saves bandwidth, not RCUs.
Why it happens
- Both parameters set at once —
Select: COUNTleft in place while aProjectionExpressionwas added (or vice versa). - Legacy
AttributesToGetcombined withSelect: COUNT. - A query builder that always attaches a projection, even when the caller only wanted a count.
- Misunderstanding
Select— expectingCOUNTto also hand back the items it counted.
How to fix it
- Just counting? Drop the projection. Set
Select: COUNTand removeProjectionExpression/AttributesToGet. - Need specific attributes? Drop
Select: COUNT. Supply aProjectionExpression; DynamoDB defaultsSelecttoSPECIFIC_ATTRIBUTES, so you usually don't setSelectat all. - Need both the count and the items? Make one call for the items (with your projection) and read its
Count, or make a separateSelect: COUNTcall. - Prefer
ProjectionExpressionoverAttributesToGet— AWS marksAttributesToGetas a legacy parameter and recommendsProjectionExpressioninstead.
Open it in DynoTable
DynoTable's query panel separates count mode from projection — you either fetch items with selected attributes or read the matched count, never both in one conflicting request. Open a table with ⌘K, run a Query, and check the result count in the status bar without attaching a ProjectionExpression.
Use the Query Builder to generate a projection-only or count-only request for your SDK code. Switch profiles with ⌘P; configure them under Settings → Profiles with Test Connection. See Connect to AWS and Install.
Sources
- Query — Amazon DynamoDB API Reference (verified 2026-07-13)
- AttributesToGet (legacy) (verified 2026-07-13)
Related errors
- Cannot use both expression and non-expression parameters — mixing legacy and expression params.
- Query key condition not supported — a malformed key condition on the same request.
- Learn: Count, sum & aggregate · Projection expressions
References
- Query — Amazon DynamoDB API Reference
- Scan — Amazon DynamoDB API Reference
- AttributesToGet (legacy) — Amazon DynamoDB Developer Guide
- Error handling with DynamoDB — Amazon DynamoDB Developer Guide
Last verified 2026-07-13 against the official AWS documentation linked above.