Cognito Users
Amazon Cognito
Amazon Cognito — a user authentication service providing user pools, JWT tokens, and group-based authorization. handles user authentication for this project. The
user pool uses email as the username, issues JWT tokens, and integrates with
API Gateway
Amazon API Gateway — a managed HTTP API service with JWT authorization, CORS, and throttling. Routes requests to the Query Lambda. to authorize requests. This page covers the
auto-created admin user, manual user management, and how group membership controls API access.
Authentication flow
Section titled “Authentication flow”When a user signs in, the flow works like this:
- User authenticates against the Cognito user pool from the web UI
- Cognito returns a JWT (ID token and access token)
- The web UI includes the token in API requests
- API Gateway
Amazon API Gateway — a managed HTTP API service with JWT authorization, CORS, and throttling. Routes requests to the Query Lambda. validates the JWT using the Cognito authorizer - If valid, the request is forwarded to the appropriate Lambda
AWS Lambda — serverless compute. This project uses two functions: ingest (RSS → embed → store) and query (search → answer). function - Group claims in the token determine endpoint access (admin vs regular user)
Auto-created admin
Section titled “Auto-created admin”When you set cognito_admin_email in your Terraform
HashiCorp Terraform — infrastructure-as-code tool used to provision all AWS resources in this demo. variables, an admin user is automatically created during terraform apply.
cognito_admin_email = "admin@example.com"During deployment, Terraform:
- Creates the user in the Cognito user pool with email verified
- Adds the user to the admin group
- Sends a temporary password to the email address
Groups and access control
Section titled “Groups and access control”The project creates a single Cognito group called admin. Group membership determines which API endpoints a user can call.
| Group | Endpoint access | Description |
|---|---|---|
admin |
| Can trigger ingestion and query the system |
| (no group) |
| Can query but cannot trigger ingestion |
Password requirements
Section titled “Password requirements”The Cognito user pool enforces the following password policy:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character
Manual user creation
Section titled “Manual user creation”First, retrieve the user pool ID from Terraform outputs:
POOL_ID="$(terraform output -raw cognito_user_pool_id)"Create a user
Section titled “Create a user”aws cognito-idp admin-create-user \ --user-pool-id "${POOL_ID}" \ --username "user@example.com" \ --user-attributes Name=email,Value=user@example.com Name=email_verified,Value=true \ --message-action SUPPRESSThe --message-action SUPPRESS flag prevents Cognito from sending a welcome email. Remove it if you want the user to receive their temporary password by email.
Set a permanent password
Section titled “Set a permanent password”aws cognito-idp admin-set-user-password \ --user-pool-id "${POOL_ID}" \ --username "user@example.com" \ --password "YourSecurePass12!" \ --permanentAdd a user to the admin group
Section titled “Add a user to the admin group”aws cognito-idp admin-add-user-to-group \ --user-pool-id "${POOL_ID}" \ --username "user@example.com" \ --group-name "admin"After adding a user to the admin group, they gain access to POST /ingest on their next sign-in (when a fresh token is issued).
Remove a user from the admin group
Section titled “Remove a user from the admin group”aws cognito-idp admin-remove-user-from-group \ --user-pool-id "${POOL_ID}" \ --username "user@example.com" \ --group-name "admin"Listing users
Section titled “Listing users”List all users in the pool
Section titled “List all users in the pool”aws cognito-idp list-users \ --user-pool-id "${POOL_ID}" \ --output tableList users in the admin group
Section titled “List users in the admin group”aws cognito-idp list-users-in-group \ --user-pool-id "${POOL_ID}" \ --group-name "admin" \ --output tableDeleting a user
Section titled “Deleting a user”aws cognito-idp admin-delete-user \ --user-pool-id "${POOL_ID}" \ --username "user@example.com"Quick reference
Section titled “Quick reference”| Action | CLI command |
|---|---|
| Create user | aws cognito-idp admin-create-user |
| Set password | aws cognito-idp admin-set-user-password |
| Add to group | aws cognito-idp admin-add-user-to-group |
| Remove from group | aws cognito-idp admin-remove-user-from-group |
| List users | aws cognito-idp list-users |
| List group members | aws cognito-idp list-users-in-group |
| Delete user | aws cognito-idp admin-delete-user |