Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Lambda@edgeで S3+CloudFrontで簡単BASIC認証!
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kazuki Miura
PRO
September 12, 2019
Technology
730
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
地域のCCoEの拡大を目指す 企業間コミュニティ 「re:light local」について
miu_crescent
PRO
0
53
us-east-1 に障害が起きた時に、 ap-northeast-1 にどんな影響があるか 説明できるようになろう!
miu_crescent
PRO
13
5.2k
これだけはやっておいた方がよさそう?awsにおけるランサムウェア対策
miu_crescent
PRO
1
160
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
4
460
なぜ あなたはそんなに re:Invent に行くのか?
miu_crescent
PRO
0
430
エンタメ方向のTを広げよう!Werner先生の クロージングキーノートを 深掘りするための小ネタ10
miu_crescent
PRO
1
210
Amazon Bedrockを活用した 報道向け文字起こしシステムの開発
miu_crescent
PRO
1
200
us-east-1 の障害が 起きると なぜ ソワソワするのか
miu_crescent
PRO
0
95
us-east-1 の障害が 起きると なぜ ソワソワするのか
miu_crescent
PRO
3
1.2k
Other Decks in Technology
See All in Technology
現場との対話から始める “作る前に問い直す”業務改善
mochico50
2
300
MCPをつなげて作る組織横断のAIエージェント基盤
tsubakimoto_s
0
160
AI時代におけるエンジニアの新たな役割──FDEとクオリアの探求/登壇資料(戸井田 裕貴)
hacobu
PRO
0
410
クラウドを使う側から、作る側へ / 大吉祥寺.pm 2026前夜祭
fujiwara3
6
1.4k
伝票作成AIエージェントを支える、LLMOpsとインフラの選択肢 / AICon2026_takeda
rakus_dev
0
290
Power Automateアップデート情報
miyakemito
0
240
OpenTelemetryにおけるGoのゼロコード・コンパイル時計装について #fukuokago
quiver
0
320
AI工学特論: MLOps・継続的評価
asei
10
2.5k
【公開用】AI_Dev_Ex2026_AI_登壇資料
matsuritechnologies
PRO
2
610
Flutter研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
100
AI_Dev_Day_製造業領域でのAI活用から見た活用の罠と成功に導く実践知.pdf
kintotechdev
0
210
Webアプリ認証の全体像 / The Big Picture of Web App Authentication
kitano_yuichi
1
450
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Abbi's Birthday
coloredviolet
3
8.8k
WENDY [Excerpt]
tessaabrams
11
39k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
500
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
740
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
A designer walks into a library…
pauljervisheath
211
24k
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 ଞʹ͍Ζ͍ΖͰ͖ΔΒ͍͠ʂ Έͳ͞Μɺͥͻ৮ͬͯΈ͍ͯͩ͘͞ʂ