Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

AWS Cognito User Pool Unconfirmed Signup Pruner

Audits AWS Cognito User Pools for abandoned unconfirmed user registrations, generating cleanup reports and security digests for IAM teams via Slack.

Categories
CloudInfrastructure

Modern SaaS applications and consumer mobile portals use Amazon Cognito User Pools for customer identity, registration workflows, and self-service password recovery. During public signups, users create accounts and receive one-time SMS or email verification codes. However, a significant fraction of registrations are abandoned by users who mistype their emails or by automated bot registration scripts probing signup endpoints. Over time, these stale accounts remain indefinitely in the UNCONFIRMED state, polluting user directories, inflating Monthly Active User (MAU) analytics, and preventing legitimate users from reusing orphaned usernames. This sentinel scans the target Cognito User Pool on a weekly schedule, detects unconfirmed accounts older than the retention threshold (e.g. 7 days), and dispatches a structured cleanup digest to IAM operations teams on Slack.

How it works

  1. Scheduled triggering: Executes weekly every Monday at 08:00 UTC via cron trigger (0 8 * * 1) or runs on-demand via manual execution.
  2. User enumeration: Calls the AWS Cognito Identity Provider API (ListUsers) using server-side filtering for cognito:user_status = "UNCONFIRMED".
  3. Registration age calculation: Evaluates the UserCreateDate timestamp of each unconfirmed account relative to current UTC time.
  4. Threshold comparison: Filters for accounts older than max_unconfirmed_age_days and compiles an actionable pruning manifest.
  5. Conditional alerting: An io.kestra.plugin.core.flow.If flowable checks if stale accounts exist and sends a cleanup summary to #iam-security-alerts.
  6. Manifest export: Emits a structured JSON audit payload detailing usernames, creation dates, and account ages for governance and automated deletion.

Architecture diagram

flowchart TD
  A[weekly_cognito_hygiene_audit Schedule Trigger] --> B[scan_unconfirmed_users Python Script]
  B --> C[check_unconfirmed_backlog Flowable If]
  C -- Stale Accounts Found --> D[notify_slack_stale_accounts Webhook]
  C -- Directory Clean --> E[log_hygiene_status Log]
  D --> E
  E --> F[export_cognito_manifest Return]

What you get

  • Automated visibility into abandoned and bot-generated user accounts cluttering Cognito directories.
  • Accurate user directory metrics without distortion from incomplete registrations.
  • Contextual Slack alerts detailing stale account counts and oldest registration dates.
  • Structured JSON manifests ready for downstream automated administrative deletion pipelines.

Who it's for

  • Identity and Access Management (IAM) Engineers maintaining customer authentication directories.
  • Security Operations (SecOps) Teams mitigating automated registration spam and credential harvesting.
  • Product and Growth Analytics Engineers requiring accurate conversion funnel and user counts.

Why orchestrate this with Kestra

Cognito User Pools do not natively feature automatic time-to-live (TTL) expiration for unconfirmed user accounts. Without programmatic intervention, unconfirmed accounts persist forever. Kestra provides scheduled orchestration with native container isolation, secret management for AWS IAM credentials, and direct Slack integration. Using Kestra, platform teams automate identity hygiene workflows safely without writing and managing bespoke Lambda cron functions.

Use cases

  • Identity Directory Hygiene: Periodically identify abandoned registration attempts where users never confirmed email or phone verification.
  • Bot Registration Detection: Spot sudden spikes in unconfirmed registrations indicative of automated bot attacks or credential stuffing.
  • Username Reclamation: Free up abandoned usernames and phone numbers so legitimate users can re-register without encountering duplicate username errors.

Inputs

Name Type Default Description
aws_region STRING us-east-1 Target AWS region where the Cognito User Pool is hosted.
user_pool_id STRING us-east-1_abcdef123 Unique identifier of the target AWS Cognito User Pool to audit.
max_unconfirmed_age_days INT 7 Threshold in days beyond which unconfirmed accounts are considered abandoned candidates for pruning.
alert_on_stale_accounts BOOL true Whether to dispatch automated Slack digests when abandoned unconfirmed users are identified.

Expected outputs

  • {{ outputs.scan_unconfirmed_users.vars.user_pool_id }}: Identifier of the evaluated Cognito User Pool.
  • {{ outputs.scan_unconfirmed_users.vars.stale_count }}: Number of unconfirmed accounts exceeding the age threshold.
  • {{ outputs.scan_unconfirmed_users.vars.has_stale_accounts }}: Boolean flag indicating whether stale registrations were discovered.
  • {{ outputs.export_cognito_manifest.value }}: Structured dictionary containing the consolidated cleanup manifest.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to AWS Cognito endpoints.
  • AWS IAM credentials configured with cognito-idp:ListUsers permissions.
  • A Slack Incoming Webhook URL configured in Kestra secrets.

Secrets

  • AWS_ACCESS_KEY_ID: AWS IAM access key with permissions to inspect Cognito user pools.
  • AWS_SECRET_ACCESS_KEY: AWS IAM secret key corresponding to the access key.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to dispatch IAM cleanup alerts.

Quick start

  1. Register AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and SLACK_WEBHOOK_URL in your Kestra secret storage.
  2. Import this blueprint into your Kestra instance under the company.cloud namespace.
  3. Update user_pool_id with your Cognito User Pool ID.
  4. Run a manual execution to test Cognito API authentication and verify the structured output.

Common pitfalls and troubleshooting

  • Pagination Limits: The Cognito ListUsers API returns up to 60 users per page; using Boto3's paginator ensures large directories are scanned completely.
  • IAM Policy Permissions: Ensure the IAM role has cognito-idp:ListUsers; missing permissions result in AccessDeniedException.
  • Filter Syntax: The filter string cognito:user_status = "UNCONFIRMED" requires exact double quotes inside the filter expression.

How to extend

  • Automated Deletion Pipeline: Add a downstream task using cognito-idp:AdminDeleteUser to automatically prune stale accounts older than 30 days after human approval.
  • Weekly Email Digest: Dispatch an HTML email summary to the security compliance team using io.kestra.plugin.email.Send.
  • Multi-Pool Matrix Audit: Wrap the evaluation in an io.kestra.plugin.core.flow.ForEach loop to audit all customer and employee user pools in the account.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.