Skip to content

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.

When a user signs in, the flow works like this:

  1. User authenticates against the Cognito user pool from the web UI
  2. Cognito returns a JWT (ID token and access token)
  3. The web UI includes the token in API requests
  4. 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
  5. 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
  6. Group claims in the token determine endpoint access (admin vs regular user)

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.

terraform.tfvars
cognito_admin_email = "admin@example.com"

During deployment, Terraform:

  1. Creates the user in the Cognito user pool with email verified
  2. Adds the user to the admin group
  3. Sends a temporary password to the email address

The project creates a single Cognito group called admin. Group membership determines which API endpoints a user can call.

GroupEndpoint accessDescription
admin

POST /ingest and POST /query

Can trigger ingestion and query the system
(no group)

POST /query only

Can query but cannot trigger ingestion

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

First, retrieve the user pool ID from Terraform outputs:

Terminal window
POOL_ID="$(terraform output -raw cognito_user_pool_id)"
Terminal window
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 SUPPRESS

The --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.

Terminal window
aws cognito-idp admin-set-user-password \
--user-pool-id "${POOL_ID}" \
--username "user@example.com" \
--password "YourSecurePass12!" \
--permanent
Terminal window
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).

Terminal window
aws cognito-idp admin-remove-user-from-group \
--user-pool-id "${POOL_ID}" \
--username "user@example.com" \
--group-name "admin"
Terminal window
aws cognito-idp list-users \
--user-pool-id "${POOL_ID}" \
--output table
Terminal window
aws cognito-idp list-users-in-group \
--user-pool-id "${POOL_ID}" \
--group-name "admin" \
--output table
Terminal window
aws cognito-idp admin-delete-user \
--user-pool-id "${POOL_ID}" \
--username "user@example.com"
ActionCLI command
Create useraws cognito-idp admin-create-user
Set passwordaws cognito-idp admin-set-user-password
Add to groupaws cognito-idp admin-add-user-to-group
Remove from groupaws cognito-idp admin-remove-user-from-group
List usersaws cognito-idp list-users
List group membersaws cognito-idp list-users-in-group
Delete useraws cognito-idp admin-delete-user