Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
cognito-userpools-in-production
Search
tannai
August 02, 2016
Technology
8.9k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
cognito-userpools-in-production
http://classmethod.connpass.com/event/35523/
#cmdevio
tannai
August 02, 2016
More Decks by tannai
See All by tannai
redash patche at dmm
yuukigoodman
0
770
akibago-2018-10-30
yuukigoodman
0
96
serverless-design-and-streaming-date-processing-service
yuukigoodman
0
1.1k
alexa-changes-development-process
yuukigoodman
0
1.7k
VUIとAlexaによるちょっと未来の体験の話2
yuukigoodman
0
950
regrowth2016alexa
yuukigoodman
0
1.4k
Rails App Deployment with CodeDeploy
yuukigoodman
0
1.6k
aws-lambda-in-practice
yuukigoodman
2
2.1k
serverless-from-today
yuukigoodman
2
2.3k
Other Decks in Technology
See All in Technology
AI時代のPRレビューにどう向き合うか?
kairim0
1
220
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
140
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
610
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
150
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
150
事業活動を AI Ready にする攻めと守りのデータエンジニアリング / data-engineering-for-ai-ready-business
pei0804
7
2.7k
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.3k
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
620
しろおびから始める!ログ活用の第一歩
shumei_ito
0
920
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
190
Loop Engineering, beyond prompt, context, and harness engineering
glaforge
0
100
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Become a Pro
speakerdeck
PRO
31
6.3k
Writing Fast Ruby
sferik
630
63k
Mind Mapping
helmedeiros
1
400
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
400
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
560
What's in a price? How to price your products and services
michaelherold
247
13k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Transcript
࣮ࡍʹ͏ Cognito UserPools Classmethod, Inc. Yuki Tannai ࣮ફSERVERLESS #cmdevio ࣮ફserverless
#cmdevio 1
ࣗݾհ • ୮༏ل • @yuukigoodman • αʔόͰಈ͘ϓϩάϥϜͱ͔AWS ࣮ફserverless #cmdevio 2
Agenda • ServerlessͱCognito • Cognito User Pools • CognitoΛ࣮ࡍʹ͏ͨΊʹ ࣮ફserverless
#cmdevio 3
Serverlessͱ Cognito ࣮ફserverless #cmdevio 4
ServerlessΞʔΩςΫνϟ ͱ ࣮ફserverless #cmdevio 5
ඇৗறܕϓϩηε ΛΠϕϯτʹΑͬͯ τϦΨʔ͢ΔΠϯϑ ϥετϥΫνϟ1 — @zerobase 1 http://qiita.com/zerobase/items/3bc0d15980b472af841d ࣮ફserverless #cmdevio
6
ServerlessΞʔΩςΫνϟͱ • ΠϯϑϥΞϓϦͷΠϕϯτΛτϦΨʔʹ࣮ߦ ͞ΕΔඇৗறϓϩηε • ίʔυͷ࣮ߦڥ͕ϑϧϚωʔδυαʔϏεͱ ͯ͠ఏڙ͞ΕΔ • AWS Lambda͕࣮ݱํ๏ͷද֨ͱͯ͠༗໊
࣮ફserverless #cmdevio 7
serverlessͰղܾ͍ͨ͠ • EC2ແ͠Ͱ؆୯ͳϓϩάϥϜΛӡ༻͍ͨ͠ • ӡ༻ͷखؒ • ͓ۚͷઅ • ΞϓϦέʔγϣϯ͔Βຊ࣭Ͱͳ͍ίʔυΛগͳ ͍ͨ͘͠
LambdaҎ֎ͷΞϓϩʔν͋Δ ࣮ફserverless #cmdevio 8
Amazon Cognito ࣮ફserverless #cmdevio 9
Cognitoͱ • ΞϓϦέʔγϣϯͷೝূɾೝՄΛαϙʔτ͢Δ ϑϧϚωʔδυαʔϏε ࣮ફserverless #cmdevio 10
• Cognito Identity • Federated Identity • User Pools •
Cognito Sync • Sync Store • Cognito Events • Cognito Streams ࣮ફserverless #cmdevio 11
Cognito Identity • ֎෦Ͱೝূ͞ΕͨϢʔβʹରͯ͠ػೳΛఏڙ͢ Δ • Federated Identity • ֎෦ͷೝূαʔϏε͔Βͷ໊دͤ
• ಗ໊Ϣʔβͱͯ͠ͷೝূՄೳ • ෳͷIdentity ProviderΛͻͱͭͷIdentity ͱͯ͠ϚʔδͰ͖Δ ࣮ફserverless #cmdevio 12
• STS • AWSͷΞΫηεΩʔΛ҆શʹൃߦ͢Δ • AssumeRoleConditionઅͳͲIAMͱͷ࿈ ܞ ࣮ફserverless #cmdevio 13
࣮ફserverless #cmdevio 14
࣮ફserverless #cmdevio 15
Cognito Sync • ϢʔβσʔλͷಉظػೳΛఏڙ • Sync Store • KVSͷΑ͏ʹ͑ΔσʔλετΞ •
SDKܦ༝ͳΒϩʔΧϧετϨʔδͱͷ࿈ܞ ؆୯ ࣮ફserverless #cmdevio 16
• Cognito Streams • SyncΠϕϯτΛड৴ͯ͠Kinesis Streamsʹ ૹ৴͢Δ • Cognito Events
• SyncΠϕϯτΛड৴ͯ͠Lambda Function Λಉظ࣮ߦ͢Δ ࣮ફserverless #cmdevio 17
Cognito User Pools ࣮ફserverless #cmdevio 18
Cognito User Poolsͱ • AWS͕ఏڙ͢ΔIdentity Provider • ϢʔβͷొཧɺೝূΛߦͳ͏͜ͱ͕Ͱ͖ Δ •
Federated Identityͱ࿈ܞͰ͖Δ • ύεϫʔυMFAɺ֬ೝϝʔϧͷૹ৴ͳͲҰൠ తͳWebαʔϏεʹඞཁͳೝূػೳΛҰ௨Γ ͍࣋ͬͯΔ ࣮ફserverless #cmdevio 19
͍ͭʹGA! ࣮ફserverless #cmdevio 20
σϞ awslabs/aws-cognito-angular2-quickstart2 2 https://github.com/awslabs/aws-cognito-angular2-quickstart ࣮ફserverless #cmdevio 21
User Poolsͷػೳ ࣮ફserverless #cmdevio 22
Ϣʔβొ • ϢχʔΫͳϢʔβ໊Λઃఆ • ύεϫʔυೝূͱɺΦϓγϣϯͰMFAΛར༻ Մೳ • ύεϫʔυϙϦγʔΛઃఆՄೳ ࣮ફserverless #cmdevio
23
ΞτϦϏϡʔτ • ΘΕΔػձ͕ଟ͍ϢʔβଐੑΛઃఆՄೳ • ΤΠϦΞεʹΑͬͯɺϩάΠϯͰ༻͢Δଐੑ ΛࢦఆͰ͖Δ • ಠࣗͷΞτϦϏϡʔτΛઃఆͰ͖Δ ࣮ફserverless #cmdevio
24
ϝʔϧɾSMSͷ֬ೝͱMFA • Ϣʔβొ࣌ɺҰ࣌తͳೝূίʔυΛൃߦ͢Δ ͜ͱͰ༗ޮͳѼઌͰ͋Δ͜ͱΛ֬ೝ • ϝοηʔδͷςϯϓϨʔτฤूՄೳ • MFAͷઃఆ͕Մೳ ࣮ફserverless #cmdevio
25
σόΠετϥοΩϯά • ಉҰϢʔβ͕ϩάΠϯঢ়ଶΛҡ࣋Ͱ͖Δ ͷઃఆ • ༗ޮʹ͢ΔͱɺॳճϩάΠϯ࣌ʹೝূͱผʹ τϥοΩϯά༻్ͷτʔΫϯ͕σόΠε͝ͱʹ ൃߦ͞ΕΔ • τϥοΩϯά͕༗ޮͳMFAΛεΩοϓ͢
Δ͜ͱͰ͖Δ ࣮ફserverless #cmdevio 26
σόΠετϥοΩϯά • ཧऀɺSDKඇެ։ͷREST API͔ΒσόΠε ϦετΛऔಘͰ͖Δ • Global Sign-out(ಉҰϢʔβͷશαΠϯΞ τ)ཧऀݖݶͰͷαΠϯΞτՄೳ ࣮ફserverless
#cmdevio 27
App • ඇೝূϢʔβ͕ϩάΠϯύεϫʔυ࠶ൃߦͳ ͲͷAPIΛ࣮ߦ͢ΔͨΊͷΤϯςΟςΟ • TokenͱSecretɻϒϥβΞϓϦSecretΛ Θͳ͍͜ͱͰ͖Δ ࣮ફserverless #cmdevio 28
App • ྫ͑ϓϥοτϑΥʔϜ͝ͱͳͲɺෳ࡞Մ ೳ • Relying PartyͷΑ͏ͳෆಛఆͷୈࡾऀʹఏڙ͢ Δ༻్ͰΘͳ͍ ࣮ફserverless #cmdevio
29
Trigger • ॴఆͷΠϕϯτΛτϦΨʔʹͯ͠Lambda Functionͷ࣮ߦ͕Մೳ • ηΩϡϦςΟػೳͷΧελϚΠζɺΠϕϯτ τϥοΩϯάͳͲ༷ʑͳ֦ு͕Մೳ ࣮ફserverless #cmdevio 30
Cognito Identity࿈ܞ • Federated IdentityͷϓϩόΠμͱͯ͠ར༻Մ ೳ • User PoolsೝূϢʔβʹରͯ͠AWSϦιʔε ͷΞΫηεݖݶΛ҆શʹൃߦͰ͖Δ
࣮ફserverless #cmdevio 31
࣮ફserverless #cmdevio 32
API Gateway࿈ܞ • API GatewayͰͷೝՄͰɺUser Poolsͷೝূ ใΛར༻Ͱ͖Δ • API GatewayͷϚωδϝϯτίϯιʔϧ͔Β
User PoolΛઃఆ͢Δ ࣮ફserverless #cmdevio 33
࣮ફserverless #cmdevio 34
CognitoΛ ࣮ࡍʹ͏ͨΊʹ ࣮ફserverless #cmdevio 35
ϙϦγʔม • CognitoʹׂΓͯΒΕΔIDʹҰக͢ΔϦιʔ εͷΈͷݖݶൃߦ • αʔόΛհ͞ͳ͍ॲཧΛ҆શʹߦ͑Δ • IAMͷConditionઅʹมΛهࡌ ࣮ફserverless #cmdevio
36
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [
"dynamodb:Query" ], "Resource": [ "arn:aws:dynamodb:ap-northeast-1:<Account ID>:table/projects", "arn:aws:dynamodb:ap-northeast-1:<Account ID>:table/projects/index/*" ], "Condition": { "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": [ "${cognito-identity.amazonaws.com:sub}" ] } } } ] } ࣮ફserverless #cmdevio 37
S3ͷ߹5 { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action":
["s3:ListBucket"], "Resource": ["arn:aws:s3:::EXAMPLE-BUCKET-NAME"], "Condition": {"StringLike": {"s3:prefix": ["cognito/mynumbersgame/"]}} }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject", "s3:DeleteObject" ], "Resource": [ "arn:aws:s3:::EXAMPLE-BUCKET-NAME/cognito/mynumbersgame/${cognito-identity.amazonaws.com:sub}", "arn:aws:s3:::EXAMPLE-BUCKET-NAME/cognito/mynumbersgame/${cognito-identity.amazonaws.com:sub}/*" ] } ] } 5 http://docs.aws.amazon.com/jajp/IAM/latest/UserGuide/accesspolicies_examples.html#iam- policy-example-cognito ࣮ફserverless #cmdevio 38
͜ͷΑ͏ͳม͕ར༻Մೳ3 • ${cognito-identity.amazonaws.com:sub} • ${www.amazon.com:user_id} • ${accounts.google.com:sub} • ${graph.facebook.com:id} 3
http://docs.aws.amazon.com/ja_jp/amazondynamodb/latest/developerguide/specifying- conditions.html http://docs.aws.amazon.com/ja_jp/amazondynamodb/latest/developerguide/ WIF.RunningYourApp.html ࣮ફserverless #cmdevio 39
OIDC Provider • Web/UserPoolsͷଞʹFederated Identityʹઃ ఆՄೳͳIdentity Provider • GoogleSalseforceͳͲ •
IAMʹOIDC ProviderΛՃ͠ɺFederated Identityʹઃఆ͢Δ • SAML͑ΔΑ͏ʹͳΓ·ͨ͠ ࣮ફserverless #cmdevio 40
࣮ફserverless #cmdevio 41
େྔϦΫΤετ࣌ͷ੍ݶ • ʮ1 ͭͷϦετ/API ࢀরݺͼग़͠ͷ࠷େ 60ʯ4 • ΞϓϦ͔Βͷݺͼग़͠ͷ੍ݶແ͍ʁ • ؒҧ͑ͯผϦʔδϣϯΛݺͼ·ͬͯͨ࣌͘
ʹʮ੍ݶ͠ͱ͍ͨΑʯͱݴΘΕͨ 4 http://docs.aws.amazon.com/ja_jp/cognito/latest/developerguide/limits.html ࣮ફserverless #cmdevio 42
Trust Relationship • ͲͷTokenൃߦऀʹରͯ͠Assume RoleΛڐՄ ͢Δ͔ͷϙϦγʔ • cognitoͷΟβʔυ͔ΒRoleΛ࡞ΔͱͪΌΜ ͱઃఆ͞Ε͍ͯΔ •
ࣗͰฤू͢ΔͱϋϚΔͷͰҙ AccessDenied -- Not authorized to perform sts:AssumeRoleWithWebIdentity ࣮ફserverless #cmdevio 43
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": {
"Federated": "cognito-identity.amazonaws.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "cognito-identity.amazonaws.com:aud": "us-east-1:aaaa-bbbb-cccc-dddd-1111-2222" }, "ForAnyValue:StringLike": { "cognito-identity.amazonaws.com:amr": "authenticated" } } } ] } ࣮ફserverless #cmdevio 44
• audͰCognito Identity Pool IDΛࢦఆ • amrͰϓϩόΠμΛࢦఆ • ྫ͑facebookͷ߹ "ForAnyValue:StringLike":
{ "cognito-identity.amazonaws.com:amr": "graph.facebook.com" } ࣮ફserverless #cmdevio 45
·ͱΊ ࣮ફserverless #cmdevio 46
• User PoolsͰೝূػೳΛAWSʹҠͤΔ • Cognito Identityͱ࿈ܞͯ͠ߋʹػೳΛAWSʹ ҠͤΔ • ࣗͷϏδωεʹԊ͏ΓํͰαʔόϨεʹ ͔͍ͬͯ͜͏
࣮ફserverless #cmdevio 47
End ࣮ફserverless #cmdevio 48