Amazon Cognito Adds Per-Device Session Management

Resumo

Pixel shares a guide to building a Cognito My Devices page with the Serverless Framework, TypeScript, and Lambda. It covers listing and revoking individual sessions, support tools for suspicious sign-ins, session limits, and why previously issued access tokens may remain valid until expiration.

DEV Community

Cognito session management: sign out devices with Lambda

Cognito session management answers a question that every app with a login hears sooner or later: “Where am I actually signed in, and how do I kick out that old tablet?” Until now, Amazon Cognito gave you two options: sign the user out everywhere at once, or build your own table of refresh tokens. Since November 11, 2026, Cognito can list the sessions of an account by itself and end them one at a time. I care about this because a “My devices” page is no longer a luxury. People who share an account, lose a phone or suspect misuse simply expect it. In this article you build that page with the Serverless Framework, TypeScript and two small Lambda functions for a fictional bike rental called “Speichenwerk”. On top, there is a support function your team can use to end suspicious sessions. In short With the new session management, Cognito lists every active sign-in of an account across devices and app clients and ends them individually, optionally together with linked sessions. You have to turn the feature on per user pool, and it requires the Essentials or Plus feature plan. The biggest pitfall: an access token that was already issued stays valid until it expires if your API only checks it locally. What you will learn in this article how SSO sessions and token sessions differ in Cognito how to build a “My devices” API with HTTP API, JWT authorizer and Lambda how support can end sessions, including linked sessions how to pick session limits and SSO validity per app client why short-lived access tokens matter after a sign-out What is Cognito session management? Cognito session management is an extension of user pools, the user directory in Amazon Cognito. Once it is on, Cognito keeps a server-side record for every sign-in: when it started, when it was last active, which device type it came from, which IP address and which city. New API calls let you read that list and end individual entries. Before, Cognito offered essentially two tools. RevokeToken revokes a refresh token the app still holds. GlobalSignOut signs the user out everywhere. The middle ground was missing: signing out one specific device whose tokens you never see. That is exactly the gap the feature fills. SSO sessions and token sessions Cognito knows two kinds of sessions. An SSO session is created when someone signs in through managed login, the sign-in page that Cognito hosts. It lives in a browser cookie and lets the user open other app clients of the same user pool without typing the password again. A token session is created on every sign-in to an app client and follows the lifecycle of the refresh token that client received. One detail helps a lot: a token refresh does not create a new session, it extends the existing one. Only a real new sign-in creates a new token session. If that sign-in came through an SSO session, the token session remembers its “parent” in the field OriginSessionId. One SSO session can carry several token sessions, a direct sign-in through the SDK has no SSO session. The sid claim in the token With session management turned on, Cognito adds a sid claim to ID and access tokens. A claim is a field inside the JSON Web Token (JWT). Its value stays the same across all refreshes of a session, so you can use it in logs or for your own checks. Watch out if you have a pre token generation trigger that sets its own sid: Cognito leaves your claim alone, and session management has no effect for the whole pool. Cognito session management compared to RevokeToken Before you build anything, it helps to put the tools side by side. The new calls do not replace the old ones, they cover different situations. Call Who calls it? What for? RevokeToken App with refresh token normal sign-out on the current device ListUserSessions User with access token show “My devices” RevokeUserSession User with access token sign out another device of your own AdminListUserSessions Backend with IAM permissions support view, suspected misuse AdminRevokeUserSession Backend with I...
Amazon Cognito Adds Per-Device Session Management
Powered by Readybot.io

As últimas novidades de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …