Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[HIGOBASHI.AWS] #6 CloudFront を使ってみよう!/ Let's u...

maru1981
August 29, 2018

[HIGOBASHI.AWS] #6 CloudFront を使ってみよう!/ Let's use CloudFront

HIGOBASHI.AWS #6 の登壇資料です

maru1981

August 29, 2018
Tweet

More Decks by maru1981

Other Decks in Technology

Transcript

  1. !3 ࣗݾ঺հ ؙໟ ಞ࢙ʢϚϧϞΞπγʣ AWS ࣄۀຊ෦ ίϯαϧςΟϯά෦ॴଐ • ιϦϡʔγϣϯΞʔΩςΫτ •

    2018೥1݄ʹ Join - 18೥ؒɺਆށͷ SIer ͰΠϯϑϥΤϯδχΞ • ޷͖ͳ AWS αʔϏε - CloudFront / Lambda@Edge
  2. ࠓ೔ɺ࿩͢͜ͱ࿩͞ͳ͍͜ͱ   • ࿩͢͜ͱ • CloudFront Λ࢖͏ࡍͷઃఆ߲໨ͳͲ • ࿩͞ͳ͍͜ͱ

    • CloudFront ͷࡉ͔ͳػೳɺੑೳͳͲ
 ʢAWS Black Belt Λ؍͍ͯͩ͘͞ʣ
 ɹhttps://aws.amazon.com/jp/aws-jp-introduction/
  3. 4όέοτϙϦγʔʢΦϦδϯΞΫηεΞΠσϯςΟςΟʔʣ   { "Version": "2008-10-17", "Id": "PolicyForCloudFrontPrivateContent", "Statement": [

    { "Sid": "1", "Effect": “Allow", "Principal": { "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QTWXXXHMIAHQ" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<όέοτ໊>/*" } ] }
  4. ΦϦδϯઃఆʢΧελϜΦϦδϯʣ   { "Version": "2008-10-17", "Id": "PolicyForCloudFrontPrivateContent", "Statement": [

    { "Sid": "1", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<όέοτ໊>/*" } ] } 48FCϗεςΟϯά͕ΦϦδϯͷ৔߹ɺό έοτϙϦγʔͰ$MPVE'SPOU͕ (FU0CKFDUग़དྷΔΑ͏ʹઃఆ͕ඞཁɻ ࠨهͷྫ͸ɺʮύϒϦοΫެ։ʯʹͳΓ·͢ɻ
  5. ΦϦδϯઃఆʢΧελϜΦϦδϯʣ   ɾ)5510OMZ
 ɹˠ$MPVE'SPOUͰऴ୺
 ɾ)55140OMZ
 ɹˠऴ୺ͤͣʹΦϦδϯʹྲྀ͢
 ɹʢΦϦδϯଆʹ΋ূ໌ॻ͕ඞཁʣ
 ɾ.BUDI7JFXFS
 ɹˠΞΫηεݩͷࢦఆʹैͬͯ


    ɹɹ্هͷ͍ͣΕ͔ ɾ0SJHJO3FTQPOTF5JNFPVU
 ɹˠΦϦδϯ͔ΒͷԠ౴଴ͪ࣌ؒ
 ɾ0SJHJO,FFQBMJWF5JNFPVU
 ɹˠΦϦδϯؒͷ5$1઀ଓͷ࣋ଓ࣌ؒ
 ɾ)5511PSU)55141PSU
 ɹˠΦϦδϯͷ-*45&/ϙʔτ൪߸
  6. Ωϟογϡಈ࡞ʢ#FIBWJPSʣઃఆ   ࡞੒ޙɺݸผͷ1BUI1BUUFSO͸࡞੒Ͱ͖·͢ $MPVE'SPOUͷϓϩτίϧϙϦγʔ
 ڐՄ͢Δ)551ϝιου
 Ωϟογϡ͢Δ)551ϝιου
 ɾ(&5ɺ)&"%ɺʢ015*0/4ʣͷΈ
 ɾͦͷଞ͸Ωϟογϡ͠·ͤΜ
 ϑΟʔϧυϨϕϧ҉߸Խɿ


    ػີσʔλʢΫϨδοτ൪߸ͳͲʣѻ͏৔߹ɺ)5514಺ Ͱߋʹ҉߸Խɻ1$*%44ͷίϯϓϥΠΞϯεཁ݅ͳͲɻ
 ʢύϒϦοΫΩʔϓϥΠϕʔτΩʔ࡞੒ඞཁʣ
 ɾઃఆޙ͸ ϦΫΤετຖʹ
  7. Ωϟογϡಈ࡞ʢ#FIBWJPSʣઃఆ   ϦΫΤετϔομʹجͮ͘Ωϟογϡઃఆ
 l/POFzɿσϑΥϧτϔομͷΈసૹ͞ΕΔɻ
 ɹɹɹɹɹམͱ͞ΕΔϔομ౳͸ϚχϡΞϧࢀর
 
 l8IJUFMJTUzɿࢦఆ͞Εͨϔομ͢΂ͯͷ஋ʹ
 ɹɹɹɹɹɹɹج͖ͮΩϟογϡ͞ΕΔɻ
 ɹɹɹɹɹɹʢࢦఆ͞Εͨϔομ͸ΦϦδϯʹ


    ɹɹɹɹɹɹɹసૹ͞ΕΔʣ
 
 l"--zɿɹ͢΂ͯͷϔομΛΦϦδϯʹసૹ
 ɹɹɹɹɹ$MPVE'SPOU͸ΦϒδΣΫτΛ
 ɹɹɹɹɹΩϟογϡ͠·ͤΜ
 ɹɹɹɹɹ ଟ͘ͷϔομΛࢦఆ͢ΔͱΩϟογϡޮ཰͕Լ͕Δ
 ˠΦϦδϯͷෛՙ͕͕͋Δ
 ·ͨɺϔομͷ஋͸େจࣈখจࣈΛ۠ผ͠·͢
 ʢϔομ໊͸۠ผ͞Εͳ͍ʣ
  8. Ωϟογϡಈ࡞ʢ#FIBWJPSʣઃఆ   $PPLJFʹجͮ͘Ωϟογϡɿ
 l/POFzɿ
 $PPLJFʹجͮ͘ΩϟογϡΛ͠ͳ͍ɻ
 4ΦϦδϯ͓Αͼ$PPLJFΛॲཧ͠ͳ͍ΦϦδ ϯʹ͸/POF͕ਪ঑ɻ
 ʢ$PPLJFͷ஋ͰԠ౴͕มΘΒͳ͍৔߹ɺ
 ɹΩϟογϡޮ཰͕Լ͕Δ͚ͩʣ


    
 l8IJUFMJTUzɿ
 8IJMUFMJTUʹͳ͍$PPLJF͸͢΂ͯ࡟আ͞Ε· ͢ɻࢦఆ͞Εͨ$PPLJF͓Αͼͦͷ஋ʹج͖ͮ Ωϟογϡ͢Δɻ
 
 l"--zɿ
 ͢΂ͯͷ$PPLJFΛΦϦδϯʹసૹɻ$PPLJF ͓Αͼͦͷ஋ʹج͖ͮΩϟογϡ͢Δɻ $PPLJF໊ͱ஋͸େจࣈখจࣈΛ۠ผ͠·͢
 ˠྫ͑͹+BQBOɺ+"1"/͸ผͷΩϟογϡͱͯ͠ॲཧ͞ΕΔ
 ˠΩϟογϡޮ཰Λ্͛ΔͨΊʹ͸ඪ४Խͨ͠ํ͕ྑ͍
  9. Ωϟογϡಈ࡞ʢ#FIBWJPSʣઃఆ   ΫΤϦจࣈྻʹجͮ͘Ωϟογϡɿ
 l/POFzɿ
 ΦϦδϯ͕ΫΤϦจࣈྻʹؔ܎ͳ͘ಉ͡όʔ δϣϯΛฦ͢৔߹ɻ
 
 l'PSXBSEBMM DBDIFCBTFEPOXIJUFMJTUzɿ


    ΦϦδϯ͕ͭҎ্ͷΫΤϦจࣈྻύϥϝʔ λʹج͍ͮͯΦϒδΣΫτͷόʔδϣϯ͕ҟ Δ৔߹ʹબ୒ɻ
 
 l'PSXBSEBMM DBDIFCBTFEPOBMMɿ
 ΦϦδϯαʔό͕͢΂ͯͷΫΤϦจࣈྻύϥ ϝʔλʹ͍ͭͯΦϒδΣΫτͷόʔδϣϯ͕ ҟΔ৔߹ʹબ୒ɻ ύϥϝʔλ໊ͱ஋ͷ྆ํͰେจࣈখจࣈΛ۠ผ͠·͢
 ύϥϝʔλॱং͕ҟΔͱผͷΦϒδΣΫτͱͯ͠Ωϟογϡ͠·͢ɻ ʢΩϟογϡޮ཰Λ্͛Δʹ͸ඪ४Խͤ͞Δ͜ͱʣ
 ˠUFTUIUNM DPMPSSFETJ[FMBSHFͱ
 ɹUFTUIUNM TJ[FMBSHFDPMPSSFE͸ผͷΦϒδΣΫτʹͳΔ
  10. σΟετϦϏϡʔγϣϯઃఆ   ྉۚΫϥεɿ
 l6TF0OMZ64 $BOBEBBOE&VSPQFz
 l6TF64 $BOBEB &VSPQF "TJBBOE"GSJDBz


    l6TF"MM&EHF-PDBUJPOTʢ#FTU1FSGPSNBODFʣz
 ೆถͳͲߴίετͷϦʔδϣϯΛ֎͢৔߹͸ɺมߋɹɹɹ "848"'΢Σϒ"$-ɿ
 $MPVE'SPOUʹ"848"'Λઃఆ͢Δ৔߹ɻ
 *1੍ݶͳͲ8"'Λར༻͢Δͱ؆୯ʹઃఆՄೳɻ
 ΑΓߴ౓ͳ੍ݶ΋ɻ΢Σϒ"$-ઃఆ͸"848"'؅ ཧը໘͔Βɻɹɹ ୅ସυϝΠϯ໊ʢ$/".&ʣɿ
 YYYDMPVEGSPOUOFUͰ͸ͳ͘ɺΧελϜυϝΠϯͰΞΫηε͍ͤͨ͞৔߹ʹ̍ͭҎ্ࢦఆ
 %/4αʔϏεͰ$/".&Ϩίʔυͷొ࿥ඞཁ
 ஫ҙɿΞΧ΢ϯτ಺֎ʹؔΘΒͣɺ͢Ͱʹ$/".&ઃఆ͞Ε͍ͯΔ୅ସυϝΠϯ໊͸ࢦఆग़དྷ·ͤΜɻ
 ʢॏෳͰ͖ͳ͍ˠ$MPVE'SPOUͱ͍͏"84ͷڊେͳαʔόʹ໊લϕʔεͷόʔνϟϧϗετߏ੒͢ΔΠϝʔδʹ͍ۙʣ
  11. σΟετϦϏϡʔγϣϯઃఆ   DMPVEGSPOUOFUͰ࢖༻͢Δ৔߹
 ηΩϡϦςΟϙϦγʔ͸ɺ
 ࣗಈతʹʮ5-4WʯʹͳΓ·͢ 44-ূ໌ॻ ΧελϜ44-ূ໌ॻɿ
 "84$FSUJpDBUF.BOBHFS "$.

    ʹొ࿥͞Εͨূ໌ॻ͔Βબ୒ɻ
 "$.ͷແྉূ໌ॻ͕ར༻Մೳ
 ˠূ໌ॻ͸ʮόʔδχΞʯϦʔδϣϯͰ࡞੒͕ඞཁ
  12. σΟετϦϏϡʔγϣϯઃఆ   αϙʔτ͞ΕΔ)551όʔδϣϯɿ
 ɹɹɹɹ σϑΥϧτϧʔτΦϒδΣΫτɿ
 ΦϒδΣΫτࢦఆͷͳ͍ΞΫηεʹରͯ͠ಛఆͷυΩϡϝ ϯτΛฦ͢৔߹ʹઃఆ
 ྫʣ
 ɾIUUQTFYBNQMFDPN


    ˠIUUQTFYBNQMFDPNJOEFYIUNMͱͯ͠ॲཧ
 
 ஫ҙɿ
 αϒσΟϨΫτϦʹ͸ରԠ͠·ͤΜɻ
 ɾIUUQTFYBNQMFDPNTVC
 ɹɹˠJOEFYIUNM͸ฦΓ·ͤΜɻΦϦδϯଆͰཁରԠɻ
 ɹɹˠ4ΦϦδϯͷ৔߹ɺͲ͏͢Δɾɾɾ
  13. σΟετϦϏϡʔγϣϯઃఆ   ΞΫηεϩάͷ༗ޮԽɿ
 ϦΞϧλΠϜʹ͸഑৴͞Ε·ͤΜʢϕετΤϑΥʔτʣ
 ·ͨɺكʹҰ੾഑৴͞Εͳ͍͜ͱ΋͋Δɻ อଘઌͷόέοτ͓ΑͼɺϓϨϑΟοΫεͷࢦఆɿ
 ඞཁͳΞΫηείϯτϩʔϧϦετʢ"$-ʣ͸ࣗಈతʹ෇༩ $PPLJFͷϩάͷ࡞੒ɿ *1WΛ༗ޮʹ͢Δɿ


    ॺ໊෇͖63-·ͨ͸ॺ໊෇͖$PPLJFΛ࢖༻͠ɺ*Q"EESFTTύϥ ϝʔλʹΑΔΞΫηε੍ݶΛ͍ͯ͠Δ৔߹ɺ*1W͸༗ޮʹ͠ͳ͍ σΟετϦϏϡʔγϣϯͷঢ়ଶɿ
 σϓϩΠޙʹσΟετϦϏϡʔγϣϯΛ༗ޮɺ
 ·ͨ͸ແޮʹ͢Δ͔Λબ୒ Ͱɺ࡞੒ʂ
  14. Ωϟογϡ࡟আ΋Ͱ͖·͢   *OWBMJEBUJPOͰΩϟογϡΛ࡟আ͢Δ͜ͱ΋Մೳ
 ɾޡͬͨΩϟογϡͷ࡟আ
 ɾΩϟογϡΛ࡟আ͠ɺଈ࣌൓ө͍ͤͨ͞ɹ
 
 ஫ҙɿ
 *OWBMJEBUJPO͸ɺ݄ؒύεҎ্͔Β
 ϦΫΤετύεຖʹ՝ۚ͞Ε·͢ɻ


    ର৅͸ύε਺ʢΦϒδΣΫτ਺Ͱ͸ͳ͍ʣ
 JNBHF Ͱ഑Լͷ ΦϒδΣΫτΛແޮԽ ͯ͠΋Χ΢ϯτ͸ύεɻ
 JNBHFUFTUKQHͷࢦఆ΋Χ΢ϯτ͸ύε
 
 ಉ࣮࣌ߦͰ͖ΔϫΠϧυΧʔυͷ*OWBMJEBUJPO͸
 ύε·Ͱͷ੍ݶ
  15. ·ͱΊ   • ΦϦδϯʹ͸ʮS3ΦϦδϯʯʮΧελϜΦϦδϯʯ͕͋Δ • λΠϓʹΑͬͯग़དྷΔ͜ͱɺग़དྷͳ͍͜ͱ͕͋Δ • Ωϟογϡͤ͞ͳ͍৔߹͸ɺ”Cache Based

    on Selected Request Headers” Λ “ALL” ʹ͢ΔɻʢTTL = 0 Ͱ͸ͳ͍ʣ • ϔομɺCookieɺΫΤϦจࣈྻ Ͱ͸ɺผόʔδϣϯͱ൑ఆ ͞ΕΔج४͕ҟͳΔʢେจࣈখจࣈɺॱংͳͲʣ