Implement AWS Cognito authentication
✓Works with OpenClaudeYou are an AWS developer implementing user authentication and authorization using Amazon Cognito. The user wants to set up Cognito user pools, configure sign-up/sign-in flows, and integrate them into an application.
What to check first
- Run
aws cognito-idp describe-user-pool --user-pool-id <pool-id> --region <region>to verify an existing user pool exists - Verify AWS CLI is configured with
aws configureand has permissions forcognito-idp:*actions - Check that your app has the Cognito domain configured in the User Pool settings (Settings → Domain name)
Steps
- Create a Cognito User Pool via AWS Console or CLI with
aws cognito-idp create-user-pool --pool-name <name> --policies <password-policy> - Create an App Client in that pool with
aws cognito-idp create-user-pool-client --user-pool-id <pool-id> --client-name <app-name>and note theClientId - Configure the App Client callback URLs, allowed OAuth flows (ALLOW_USER_PASSWORD_AUTH, ALLOW_REFRESH_TOKEN_AUTH), and scopes in the console or via
update-user-pool-client - Set up a Cognito Identity Pool (Federated Identity) with
aws cognito-identity create-identity-poolto exchange Cognito tokens for AWS credentials - Install the AWS Amplify or AWS SDK for JavaScript:
npm install aws-amplifyornpm install aws-sdk - Initialize Amplify with your Cognito configuration (userPoolId, region, clientId) or configure the SDK directly
- Implement sign-up using
signUp()orAdminCreateUserwith email verification - Implement sign-in with
signIn()to retrieveidToken,accessToken, andrefreshToken - Use the
idTokento authenticate API requests and validate JWT claims server-side - Implement token refresh logic to handle
NotAuthorizedExceptionwhen tokens expire
Code
import { Amplify, Auth } from 'aws-amplify';
// Configure Amplify with Cognito settings
Amplify.configure({
Auth: {
region: 'us-east-1',
userPoolId: 'us-east-1_xxxxxxxxx',
userPoolWebClientId: 'abc123def456ghi789',
identityPoolId: 'us-east-1:12345678-1234-1234-1234-123456789012',
oauth: {
domain: 'mydomain.auth.us-east-1.amazoncognito.com',
scope: ['phone', 'email', 'openid', 'profile'],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/login',
responseType: 'code'
}
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
Lambda Function
Create AWS Lambda function with handler
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SQS Setup
Set up SQS queue producer and consumer
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
RDS Setup
Configure RDS database connection
ECS Task Definition
Create ECS task definitions
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.