Granting access to
downloadable [paid]
resources in mobile app
using AWS Cognito + Lambda + IAM + S3
Goal
● we have paid downloadable content (in the
form of JSON files on Amazon S3)
● we need to give access to content from
mobile application to specific users
Options
● Using signed URLs in Amazon S3
● Managing access with custom developed
backend
or
● Amazon Cognitor + Lambda + IAM + S3
Granting access to Quest
● each Quest is saved as Amazon S3 object in
JSON format
● Objects are not accessible publicly
● When user buys or open Quest in
application, we need to update Amazon IAM
Role policy
Amazon IAM policy
'{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::zequest*"],
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:sub": ["us-east-1:3abb829b-82c1-4ac5-85fa-4dc566c6acfb"]
}
}
}
]
}'
Content access is granted through Resource section
User is identified with Cognito IdentityId
1. User can be non-
authenticated until “Go to
quest” phase
2. Non-authenticated user is
proposed to authenticate with
Facebook/Twitter/Google+
3. Every user gets Cognito
IdentityId (used in IAM
policies)
1. User select content and click
“Download” (running man
icon on image)
2. Depending on content type
(in-app purchase or free)
user passes (or skip)
payment phase
Update Amazon Cognito dataset
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:123123123123123123123',
});
AWS.config.credentials.get(function() {
var syncClient = new AWS.CognitoSyncManager();
syncClient.openOrCreateDataset('quests', function(err, dataset) {
dataset.put('123456789', 'yourJSONValueForQuestData', function(err,
record){
dataset.synchronize({
onSuccess: function(data, newRecords) {
console.log("successful");
}
});
});
});
});
https://gist.github.com/werdan/3d8b7ad34cf60649a074
NB!
Synchronization
is done only if there are changes
in dataset
Amazon Cognito - Lambda events
● on Cognito dataset synchronization you can
launch Amazon Lambda function
● This function, using AWS IAM API, updates
Policy for authenticated user (using Cognito
IdentityId)
● Amazon Lambda event handling is
synchronous
Amazon Lambda pseudo-code
● get Cognito IdentityId
● get current policy for this user
● update policy with access to new Amazon
S3 object
Amazon Lambda example
var AWS = require('aws-sdk');
var iam = new AWS.IAM();
var params = {
RoleName: 'Cognito_ZeQuestAuth_Role',
PolicyDocument: JSON.stringify(policy),
PolicyName: "us-east-1@3abb829b-82c1-4ac5-85fa-4dc56612313213"
};
iam.putRolePolicy(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
Questions?
Andriy Samilyak
ansam@opsway.com
skype: samilyaka
http://opsway.com

More Related Content

PPT
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
PPTX
Building Cloud-Powered Mobile Apps
PDF
Gaming on AWS - 8. 서버 없이 게임 만들기 - Serverless Architecture
PDF
Building Cloud-powered Mobile Apps
PDF
Build a mobile app serverless with AWS Lambda
PPTX
Building Cloud-powered Mobile Apps
PDF
Building Event-driven Serverless Apps
PDF
Building Event-Driven Serverless Applications
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
Building Cloud-Powered Mobile Apps
Gaming on AWS - 8. 서버 없이 게임 만들기 - Serverless Architecture
Building Cloud-powered Mobile Apps
Build a mobile app serverless with AWS Lambda
Building Cloud-powered Mobile Apps
Building Event-driven Serverless Apps
Building Event-Driven Serverless Applications

Similar to Amazon Cognito + Lambda + S3 + IAM (20)

PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PDF
AWS Innovate 2016: Build Mobile Apps using AWS SDKs and Mobile Hub- Oliver Klein
PPTX
ACDKOCHI19 - Enterprise grade security for web and mobile applications on AWS
PDF
amazon-cognito-auth-in-minutes
PDF
Serverless Meetup - Authentication for Serverless Applications [Jul 2020]
PDF
Amazon Cognito Principles.pdf
PDF
Scaling your Mobile App Development in the Cloud - DevNexus
PDF
Serverless Meetup - Getting started with AWS Cognito [Jul 2020]
PDF
Build high performing mobile apps, faster with AWS
PDF
Complex architectures for authentication and authorization on AWS
PDF
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
PDF
NahamConEU2022.pdf
PDF
Aws(sdk)
PPTX
Null Bangalore | Pentesters Approach to AWS IAM
PPTX
Serverless-First Function: Serverless application security
PDF
Cloud-powered Cross-platform Mobile Apps on AWS
PDF
02 cloud poweredmobileappsonaws_short
PPTX
Complex architectures for authentication and authorization on AWS
PDF
Social & Mobile Apps journey through the cloud
PPTX
AWS Atlanta meetup cognit Back to Basics
Amazon Cognito: A Primer on Authentication and Authorization
AWS Innovate 2016: Build Mobile Apps using AWS SDKs and Mobile Hub- Oliver Klein
ACDKOCHI19 - Enterprise grade security for web and mobile applications on AWS
amazon-cognito-auth-in-minutes
Serverless Meetup - Authentication for Serverless Applications [Jul 2020]
Amazon Cognito Principles.pdf
Scaling your Mobile App Development in the Cloud - DevNexus
Serverless Meetup - Getting started with AWS Cognito [Jul 2020]
Build high performing mobile apps, faster with AWS
Complex architectures for authentication and authorization on AWS
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
NahamConEU2022.pdf
Aws(sdk)
Null Bangalore | Pentesters Approach to AWS IAM
Serverless-First Function: Serverless application security
Cloud-powered Cross-platform Mobile Apps on AWS
02 cloud poweredmobileappsonaws_short
Complex architectures for authentication and authorization on AWS
Social & Mobile Apps journey through the cloud
AWS Atlanta meetup cognit Back to Basics
Ad

More from Andriy Samilyak (16)

PPTX
Kaizen Magento Support - 2
ODP
Kaizen Magento support
PPTX
MageClinic: Affiliative program
PPTX
Magento - choosing Order Management SaaS
PPTX
TOCAT Introduction (English)
PPTX
TOCAT Introduction
ODP
Как мы играли в DevOps и как получился Magento Autoscale
ODP
Magento autoscaling
ODP
DevOps in realtime
ODP
Synthetic web performance testing with Selenium
ODP
Chef training - Day3
ODP
Chef training Day5
ODP
Chef training Day4
PDF
Chef training - Day1
ODP
Chef training - Day2
ODP
DevOps в реальном времени
Kaizen Magento Support - 2
Kaizen Magento support
MageClinic: Affiliative program
Magento - choosing Order Management SaaS
TOCAT Introduction (English)
TOCAT Introduction
Как мы играли в DevOps и как получился Magento Autoscale
Magento autoscaling
DevOps in realtime
Synthetic web performance testing with Selenium
Chef training - Day3
Chef training Day5
Chef training Day4
Chef training - Day1
Chef training - Day2
DevOps в реальном времени
Ad

Recently uploaded (20)

PDF
MCP Security Tutorial - Beginner to Advanced
PDF
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
Lecture 5 Software Requirement Engineering
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PDF
Microsoft Office 365 Crack Download Free
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PDF
E-Commerce Website Development Companyin india
PPTX
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
PPTX
Cybersecurity: Protecting the Digital World
PDF
Workplace Software and Skills - OpenStax
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
Computer Software - Technology and Livelihood Education
PDF
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
Visual explanation of Dijkstra's Algorithm using Python
MCP Security Tutorial - Beginner to Advanced
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
How to Use SharePoint as an ISO-Compliant Document Management System
Lecture 5 Software Requirement Engineering
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
Wondershare Recoverit Full Crack New Version (Latest 2025)
Matchmaking for JVMs: How to Pick the Perfect GC Partner
Microsoft Office 365 Crack Download Free
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
E-Commerce Website Development Companyin india
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
Cybersecurity: Protecting the Digital World
Workplace Software and Skills - OpenStax
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Computer Software - Technology and Livelihood Education
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
CNN LeNet5 Architecture: Neural Networks
Visual explanation of Dijkstra's Algorithm using Python

Amazon Cognito + Lambda + S3 + IAM

  • 1. Granting access to downloadable [paid] resources in mobile app using AWS Cognito + Lambda + IAM + S3
  • 2. Goal ● we have paid downloadable content (in the form of JSON files on Amazon S3) ● we need to give access to content from mobile application to specific users
  • 3. Options ● Using signed URLs in Amazon S3 ● Managing access with custom developed backend or ● Amazon Cognitor + Lambda + IAM + S3
  • 4. Granting access to Quest ● each Quest is saved as Amazon S3 object in JSON format ● Objects are not accessible publicly ● When user buys or open Quest in application, we need to update Amazon IAM Role policy
  • 5. Amazon IAM policy '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::zequest*"], "Condition": { "StringEquals": { "cognito-identity.amazonaws.com:sub": ["us-east-1:3abb829b-82c1-4ac5-85fa-4dc566c6acfb"] } } } ] }' Content access is granted through Resource section User is identified with Cognito IdentityId
  • 6. 1. User can be non- authenticated until “Go to quest” phase 2. Non-authenticated user is proposed to authenticate with Facebook/Twitter/Google+ 3. Every user gets Cognito IdentityId (used in IAM policies)
  • 7. 1. User select content and click “Download” (running man icon on image) 2. Depending on content type (in-app purchase or free) user passes (or skip) payment phase
  • 8. Update Amazon Cognito dataset AWS.config.region = 'us-east-1'; AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'us-east-1:123123123123123123123', }); AWS.config.credentials.get(function() { var syncClient = new AWS.CognitoSyncManager(); syncClient.openOrCreateDataset('quests', function(err, dataset) { dataset.put('123456789', 'yourJSONValueForQuestData', function(err, record){ dataset.synchronize({ onSuccess: function(data, newRecords) { console.log("successful"); } }); }); }); }); https://gist.github.com/werdan/3d8b7ad34cf60649a074 NB! Synchronization is done only if there are changes in dataset
  • 9. Amazon Cognito - Lambda events ● on Cognito dataset synchronization you can launch Amazon Lambda function ● This function, using AWS IAM API, updates Policy for authenticated user (using Cognito IdentityId) ● Amazon Lambda event handling is synchronous
  • 10. Amazon Lambda pseudo-code ● get Cognito IdentityId ● get current policy for this user ● update policy with access to new Amazon S3 object
  • 11. Amazon Lambda example var AWS = require('aws-sdk'); var iam = new AWS.IAM(); var params = { RoleName: 'Cognito_ZeQuestAuth_Role', PolicyDocument: JSON.stringify(policy), PolicyName: "us-east-1@3abb829b-82c1-4ac5-85fa-4dc56612313213" }; iam.putRolePolicy(params, function(err, data) { if (err) console.log(err, err.stack); else console.log(data); });