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.

Andreas and Michael Wittig

Hej, Andreas & Michael here!

We launched the cloudonaut blog in 2015. Since then, we have published 323 articles: small tips and tricks, best practices, and service reviews. We enjoy writing about all things AWS a lot.

Do you like our blog posts and podcast episodes? Have you learned something new? Consider supporting us create in-depth and independent AWS content. Please help us with a monthly or one-time payment through GitHub Sponsors.

Start supporting us today!

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.

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
Andreas Wittig

Andreas Wittig

I'm an independent consultant, technical writer, and programming founder. All these activities have to do with AWS. I'm writing this blog and all other projects together with my brother Michael.

In 2009, we joined the same company as software developers. Three years later, we were looking for a way to deploy our software—an online banking platform—in an agile way. We got excited about the possibilities in the cloud and the DevOps movement. It’s no wonder we ended up migrating the whole infrastructure of Tullius Walden Bank to AWS. This was a first in the finance industry, at least in Germany! Since 2015, we have accelerated the cloud journeys of startups, mid-sized companies, and enterprises. We have penned books like Amazon Web Services in Action and Rapid Docker on AWS, we regularly update our blog, and we are contributing to the Open Source community. Besides running a 2-headed consultancy, we are entrepreneurs building Software-as-a-Service products.

We are available for projects.

You can contact me via Email, Twitter, and LinkedIn.

Briefcase icon
Hire me