πŸ‘‰ AWS Debug Games (Beta) - Prove your AWS expertise by solving tricky challenges.

πŸ‘‰ AWS Debug Games - Prove your AWS expertise.

Cognito Under the Hood

Andreas Wittig – 24 Mar 2021

Have you ever implemented a user database and authentication layer yourself? There are many things to get right: Hashing and salting passwords, multi-factor authentication, brute force attacks, and many more. That’s why I recommend using a production-ready service instead of building authentication yourself. That’s what Amazon Cognito is all about.

Cognito Under the Hood

Let me start with typical use cases for Cognito:

Serverless app with API Gateway

A typical Serverless application uses Cognito User Pools for authentication and authorization.

Serverless app with API Gateway

  1. The client authenticates with the User Pool.
  2. The client sends the identity or access token as a header to the API Gateway.
  3. The API Gateway verifies the token and grants access.
  4. The API Gateway adds information from the identity/access token to the context when invoking a Lambda function.

Obtain temporary AWS credentials

Cognito Identity Pool allows federated identities to access AWS resources by issuing temporary AWS access credentials. Users can use those credentials to interact with AWS APIs directly (e.g., AppSync, S3, DynamoDB, …). That allows clients to access data stores without a backend.


Looking for a new challenge?

  • DEMICON

    Cloud Operations Lead

    DEMICON • AWS Advanced Consulting Partner • Remote (Europe)
    service-delivery-management hiring devops platform

Obtain temporary AWS credentials

Cloud-native app with ALB

You can add authentication to any cloud-native app that sits behind an ALB. ALBs support authentication/authorization based on Cognito User Pools.

Cloud native app with ALB

We use it to add a layer of security for traditional tools like Jenkins, phpMyAdmin, etc.
You can find a working example here: https://github.com/cfn-modules/docs/tree/master/examples/fargate-alb-auth-cognito

The following video covers:

  • When to use AWS Cognito?
  • Demo: ALB + Cognito User Pool
  • User Pool vs. Identity Pool
  • Pitfall: Backup your most valuable asset!

Summary

The following table helps you to decide which option to choose.

User Pool Identity Pool
Built-in User Database βœ… Yes ❌ No
Grant access to AWS resources directly βœ… Yes in combination with an Identity Pool βœ… Yes
Social Login Google, Facebook, Amazon, Apple Google, Facebook, Amazon, Apple
SAML βœ… Yes βœ… Yes
OpenID Connect βœ… Yes βœ… Yes
Hosted UI βœ… Yes ❌ No
Costs $0.0055 per Monthly Active User (MAU) Free

Become a cloudonaut supporter

Andreas Wittig

Andreas Wittig ( Email Twitter LinkedIn Mastodon )

We launched the cloudonaut blog in 2015. Since then, we have published 365 articles, 68 podcast episodes, and 68 videos. It's all free and means a lot of work in our spare time. We enjoy sharing our AWS knowledge with you.

Please support us

Have you learned something new by reading, listening, or watching our content? With your help, we can spend enough time to keep publishing great content in the future. Learn more

$
Amount must be a multriply of 5. E.g, 5, 10, 15.

Thanks to Alan Leech, Alex DeBrie, Christopher Hipwell, Jason Yorty, Jeff Finley, jhoadley, Johannes Konings, John Culkin, Jonathan Deamer, Juraj Martinka, Ken Snyder, Markus Ellers, Oriol Rodriguez, Ross Mohan, sam onaga, Satyendra Sharma, Simon Devlin, Todd Valentine, Victor Grenu, and all anonymous supporters for your help! We also want to thank all supporters who purchased a cloudonaut t-shirt.