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
Lambda@edgeで S3+CloudFrontで簡単BASIC認証!
Search
Kazuki Miura
PRO
September 12, 2019
Technology
740
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Lambda@edgeで S3+CloudFrontで簡単BASIC認証!
20190912_JAWSUG札幌_LT1
Kazuki Miura
PRO
September 12, 2019
More Decks by Kazuki Miura
See All by Kazuki Miura
Kiro Crewしか勝たん!?
miu_crescent
PRO
0
230
Kiro Crew で始める マルチエージェント開発
miu_crescent
PRO
1
280
Lambdaで動画のエンコードしたら MediaConvertに勝てるのか
miu_crescent
PRO
0
93
AWS Summit 報道現場で磨き上げた、 文字起こしシステムの開発。
miu_crescent
PRO
0
53
報道現場で磨き上げた、 ⽂字起こしシステムの開発
miu_crescent
PRO
0
52
地域のCCoEの拡大を目指す 企業間コミュニティ 「re:light local」について
miu_crescent
PRO
0
90
us-east-1 に障害が起きた時に、 ap-northeast-1 にどんな影響があるか 説明できるようになろう!
miu_crescent
PRO
13
5.4k
これだけはやっておいた方がよさそう?awsにおけるランサムウェア対策
miu_crescent
PRO
1
180
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
4
520
Other Decks in Technology
See All in Technology
Kiro Crewをはじめよう
kizawa2020
1
160
大型犬好きによるPugの紹介
yamanoku
1
160
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
100
Running Kotlin + Quarkus with Lambda
nealle
1
3.7k
Classmethod Company Deck
satoshi7
1
680
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
4.9k
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
450
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.8k
Rust で関数型ドメインモデリング
takonda
0
140
『SAR衛星データ解析入門』のご紹介とその応用
syuchimu
0
120
re:Invent初参加で変わったこと、2回目にやってみたいこと(JAWS-UG彩の国埼玉 #12)
mhrtech
2
220
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.7k
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Typedesign – Prime Four
hannesfritz
42
3.2k
Music & Morning Musume
bryan
48
7.4k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
Code Reviewing Like a Champion
maltzj
529
40k
Designing for humans not robots
tammielis
254
26k
Making the Leap to Tech Lead
cromwellryan
135
10k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
540
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Site-Speed That Sticks
csswizardry
13
1.6k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Transcript
Lambda@edgeͰ S3+CloudFrontͰɺ؆୯BASICೝূʂ 20199݄12 ୈ24ճ JAWS-UG ࡳຈ
ࡾӜҰथ ωοτσδλϧࣄۀ෦ ͖ͳAWSαʔϏε:CloudFront ͖ͳGCPαʔϏε:BigQuery
ݱ͔ΒώΞϦϯά ༁ɾ࣮ґཔ ςΫχΧϧσΟϨΫλʔʁ 43& 1.ʁ
Lambda@edge ͬͯͳʹʁ
S3 bucket CloudFront Client Linuxͱ͔ͪΐͬͱΘ͔Μͳ͍ͷͰɺ web্ཱͪ͛Α͏ͱ͢Δͱɺ͜ͷํ๏͔͠Βͳ͍ͷͰ͢ɻ CloudFront େ͖
ʮ.htaccess ͱ͔Ͳ͏͢Μͷʁʯ
ͪΐͬͱɺΘ͔Μͳ͍
S3 bucket CloudFront Client Lambda@edge BASICೝূ
Ϧʔδϣϯ όʔδχΞ෦
Node.jsͷ߹
ʮsite:dev.classmethod.jp lambda BASICೝূʯ Ͱάάͬͯɺίϐϖ https://dev.classmethod.jp/cloud/aws/basic-auth-s3-cloudfront-lambda/
'use strict'; exports.handler = (event, context, callback) => { //
Get request and request headers const request = event.Records[0].cf.request; const headers = request.headers; // Configure authentication const authUser = 'user'; const authPass = 'pass'; // Construct the Basic Auth string const authString = 'Basic ' + new Buffer(authUser + ':' + authPass).toString('base64'); // Require Basic authentication if (typeof headers.authorization == 'undefined' || headers.authorization[0].value != authString) { const body = 'Unauthorized'; const response = { status: '401', statusDescription: 'Unauthorized', body: body, headers: { 'www-authenticate': [{key: 'WWW-Authenticate', value:'Basic'}] }, }; callback(null, response); } // Continue request processing if authentication passed callback(null, request); };
'use strict'; exports.handler = (event, context, callback) => { //
Get request and request headers const request = event.Records[0].cf.request; const headers = request.headers; // Configure authentication const authUser = 'user'; const authPass = 'pass'; // Construct the Basic Auth string const authString = 'Basic ' + new Buffer(authUser + ':' + authPass).toString('base64'); // Require Basic authentication if (typeof headers.authorization == 'undefined' || headers.authorization[0].value != authString) { const body = 'Unauthorized'; const response = { status: '401', statusDescription: 'Unauthorized', body: body, headers: { 'www-authenticate': [{key: 'WWW-Authenticate', value:'Basic'}] }, }; callback(null, response); } // Continue request processing if authentication passed callback(null, request); }; ͚ͩ͜͜ɺม͑Δ
ࠓΞΫγϣϯΛԡ͢ ϙνο
෦όʔδχΞ͚ͩʮػೳʯͬͯͷ͕͋Δ ෦όʔδχΞ ౦ژ
Πϕϯτશ෦Ͱ4छྨ ࠓճʮϏϡʔΞʔϦΫΤετʯΛબ
ͪΐͬͱɺͭ
σϓϩΠυ
CloudFrontͷBehaviorͷԼͷํ ͏·͘ɺͰ͖ͯͦ͏
ΞΫηεͯ͠ΈΔ Ͱ͖ͨʂʂ
Lambda@edge ଞʹ͍Ζ͍ΖͰ͖ΔΒ͍͠ʂ Έͳ͞Μɺͥͻ৮ͬͯΈ͍ͯͩ͘͞ʂ