How to get count of all Users in DynamoDB using Swift and Soto


1 min read

This was made using Soto v7.0.0-rc1.

Assuming that your Partition Key and Sort Key are named PK and SK in your table. Also that your PK for all users are USER#.

    let input = DynamoDB.QueryInput(
      expressionAttributeNames: ["#p": "PK"],
      expressionAttributeValues: [":pk" : .s("USER#")],
      keyConditionExpression: "#p = :pk",
      select: .count,
      tableName: tableName
    let output = try await dynamoDB.query(input)

This is just a short code snippet so that I can reference it later. Subscribe for more snippets and other thoughts.