Amazon CloudFront signed cookies with Amazon Cognito using Python CDK

Amazon API Gateway → AWS Lambda → Amazon Cognito → Amazon CloudFront → Amazon S3

Implement Amazon CloudFront signed cookies for private Amazon S3 content access with Amazon Cognito user authentication using AWS CDK with Python.

This pattern creates a secure content delivery solution using CloudFront signed cookies. Users authenticate through Amazon Cognito via API Gateway Lambda functions.
Upon successful login, the Lambda function generates CloudFront signed cookies that grant time-limited access to private S3 content behind the CloudFront distribution.
The CloudFront distribution uses Origin Access Control (OAC) to securely access private S3 content. Public content is accessible without authentication, while private content requires valid signed cookies.
The signed cookies use RSA key pairs, with the private key stored securely in AWS Secrets Manager and the public key configured in a CloudFront Key Group.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/cloudfront-s3-signed-cookies-cognito

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: cdk destroy.

Created by:

Matia Rasetina

Matia Rasetina

Senior Software Engineer @ Elixirr Digital

Follow on LinkedIn