- Newest
- Most votes
- Most comments
The issue you're encountering is related to how JMESPath query expressions handle nested filtering. When you chain filters like Users[?Enabled==true].Attributes[?Name==email].Value, the query engine struggles with the nested array filtering.
The problem is that after filtering for enabled users, you're trying to apply another filter on the Attributes array, and then extract the Value. This nested filtering syntax doesn't work as expected in JMESPath.
Here are a couple of approaches that should work:
Option 1: Use a projection with filtering
aws cognito-idp list-users --user-pool-id **** --query 'Users[?Enabled==`true`].[Username, Attributes[?Name==`email`].Value | [0]]' --output table
This second option will give you both the username and email address in a table format, which matches what you mentioned wanting to see.
The key difference is that you need to handle the nested array structure more explicitly. The | [0] at the end extracts the first (and only) value from the filtered email attribute array.
If you only want email addresses in a simple list, you could also try:
aws cognito-idp list-users --user-pool-id **** --query 'Users[?Enabled==`true`].Attributes[?Name==`email`].Value | []' --output text
The flatten operator | [] helps collapse the nested array structure into a simpler format that can be displayed properly.
Sources
Use ListUsers with an AWS SDK or CLI - Amazon Cognito
list-users — AWS CLI 2.27.41 Command Reference
Option 2 provided here did succeed and return the results I am looking for.
Option 1 did not succeed, and returned a syntax error.
The final suggested query also did not succeed, it returned no results.
A solution that I have found effective combines a filter (server-side) and a query (client-side) and works for me:
aws cognito-idp list-users \
--user-pool-id **** \
--filter 'status="Enabled"' \
--query "Users[].Attributes[?Name=='email'].Value" \
--output table
Relevant content
- asked 2 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 6 months ago
