Architecture

    A serverless design, end to end

    API Gateway, Python Lambdas and a Cognito User Pool - provisioned entirely with Terraform. Here's exactly what gets deployed, what it costs, and the decisions behind it.

    Architecture Overview

    Request flow

    Store-nothing
    Client
    Your web/mobile app or the React example - sends JSON over HTTPS.
    HTTPS
    Route 53 + ACM
    Custom domain with a TLS certificate, validated and renewed automatically.
    API Gateway (REST)
    23 endpoints. CORS, with WAF + throttling recommended in front for production.
    invokes
    AWS Lambda - Python
    One focused handler per endpoint, 2 shared layers (jsonschema, PyJWT). No servers to manage.
    boto3
    Cognito User Pool
    Identities, mandatory TOTP MFA, and JWT issuance (ID / access / refresh).
    Lambda triggers
    Custom-auth (MFA reset) + custom-message (branded emails).
    Amazon SES
    Temporary passwords & one-time recovery codes.
    Identity Pool
    Optional exchange of JWTs for scoped AWS credentials.

    Observability via CloudWatch logs + lambda warmers · least-privilege IAM role per function · 100% provisioned with Terraform (remote state in S3, locked with DynamoDB).

    Deployed Resources

    QtyResourcePurpose
    1API Gateway (REST)Exposes the 23 HTTP endpoints with CORS. A Cognito JWT authorizer gates only GET /v1/userinfo and DELETE /v1/users/{id}; the rest are open (add WAF/throttling + broader authorizers for production)
    1Cognito User PoolHolds all users, enforces MFA, and issues JWTs
    1Cognito Identity PoolOptional exchange of JWTs for scoped AWS credentials
    27Lambda FunctionsEndpoint handlers (including 6 passkey handlers) plus 3 custom-auth triggers and the custom-message trigger
    2Lambda LayersShared dependencies (jsonschema, PyJWT)
    27CloudWatch Log GroupsPer-function logs, plus scheduled lambda warmers
    1ACM CertificateTLS for the API custom domain
    2Route53 RecordsACM validation + API custom domain
    1S3 BucketEncrypted, versioned Terraform remote state
    1DynamoDB TableTerraform state lock for safe collaboration

    Cost Estimation

    Estimations based on the following parameters:

    • Deployment region: eu-west-1
    • User base: 50,000 active users
    • Authentication pattern: 26 requests per user per day
    • Lambda configuration: 256MB memory, ~1s duration per call
    ServiceMonthly CostNotes
    API Gateway$351.3M requests daily
    Lambda$651.3M invocations daily
    Cognito$3050K MAU
    Other Services$20S3, DynamoDB, Route53
    TOTAL~$150$0.003 per user/month
    Hard to find a serious competitor at this price level!

    Implementation Notes

    Security First & store-nothing

    TOTP MFA is mandatory and set up at enrollment. The secret is shown to the user exactly once and never persisted server-side - recovery is a custom-auth flow (emailed code + password), not a stored secret.

    Terraform-Based

    The main IAC tool choice was based on popularity and simplicity. Terraform has been reliable since its early releases.

    Token Lifecycle

    Access and ID tokens are valid for 1 hour; refresh tokens for 24 hours. Token revocation is enabled, and all values are customizable via variables.

    Multi-Environment

    The solution uses a Makefile to handle multi-environment deployments. Create configuration files in environments/MyEnvName/terraform.tfvars.MyEnvName.

    Password Policy

    14 characters minimum length with at least 1 number, 1 special character, 1 uppercase letter and 1 lowercase letter.

    Recommendations

    • Use AWS WAF in production to protect your API against illegitimate traffic
    • Throttle the public endpoints with API Gateway per-method rate + burst limits to bound Lambda invocations (financial-DDoS defense)
    • There is no API key: authorize user endpoints with the Cognito JWT, and admin actions (user create/delete) with a machine-to-machine token kept in your backend

    Ready to implement Cognito API?

    Now that you understand the architecture, continue to our getting started guide for implementation details.