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

AWS Lambdaによるサーバレスアーキテクチャの基本に触れてみよう!【kintone & ...

AWS Lambdaによるサーバレスアーキテクチャの基本に触れてみよう!【kintone & AWS ハンズオン祭り2015秋 B-2】

「kintone & AWS ハンズオン祭り2015秋」のスライドです。

Ryu Yamashita

November 12, 2015
Tweet

More Decks by Ryu Yamashita

Other Decks in Programming

Transcript

  1. ຊ೔ͷԋ໨ 2 w LJOUPOFΤίγεςϜ w αʔόϨεΞʔΩςΫνϟ w ݁ہαʔόϨεͱ͸ʁ w αʔόϨεΞʔΩςΫνϟͷԸܙ

    w ࠓճϑΥʔΧε͢Δ"84ͷαʔϏε w "84-BNCEB w "NB[PO"1*(BUFXBZ w ϋϯζΦϯᶃ)FMMP8PSME w ϋϯζΦϯᶄ)FMMP-BNCEBΛ܁Γฦ͢ w ϋϯζΦϯᶅLJOUPOF#BDLMPH࿈ܞ w αϯϓϧμ΢ϯϩʔυ w ϋϯζΦϯϞσϧ w -BNCEBɾΠϕϯτઃఆ w "1*(BUFXBZͷઃఆ w #BDLMPHͷઃఆ w LJOUPOFͷઃఆ w -BNCEBɾؔ਺ͷઃఆ w #BDLMPH͔Βͷ՝୊ͷ௥ՃΛࢼ͢ w ϋϯζΦϯޙย෇͚ ˞εϥΠυ಺ϦϯΫ͸1%'μ΢ϯϩʔυ࣌ʹ༗ޮʹͳΓ·͢
  2. ࣗݾ঺հʮࢁԼཽʯ 3  *05ͱάϧʔϓ΢ΣΞʢσξΤʣͷ࿈ܞΛࢼΈͯLJOUPOFɹʹग़ձ͏  LJOUPOFΤόϯδΣϦετʹ  LJOUPOF޷͖͕ߴͯ͡ɺք۾ॳͷLJOUPOFస৬  LJOUPOF$BGÉӡӦࣄ຿ہ։ઃɺࣄ຿ہϝϯόʔʹ

     LJOUPOF$BGÉ෱Ԭ7PMΛओ࠵ ݱࡏ ଟ෼ɺl೔ຊͰ།ҰLJOUPOFͰ͝൧৯΂ͯΔਓz גࣜձࣾδϣΠκʔɹࢁԼཽʢʣ෱Ԭݝେໂాࢢग़਎ ʮϒϧʔ΢Σʔϒʯ ͱ͍͏ڞ௨఺
  3. LJOUPOFΤίγεςϜʢLJOUPOFͱ"84ʣ 9 w ΞϓϦέʔγϣϯدΓ1BB4 4BB4  w ΫϥΠΞϯταΠυϑϩϯτΤϯυ ʢ6*69ʣ w

    ߦಈతղऍͷڞ༗ͰΞΫγϣϯΛى͜͠ɺ ίϛϡχέʔγϣϯͰۀ຿Λճ͢ w ΠϯϑϥدΓ1BBT *BB4ɺ#BB4  w αʔόʔαΠυόοΫΤϯυɹɹɹ ίϚϯυ  w ࢥߟతσʔλΛࡹ͖ࣄ৅Λղऍ͢Δ "1*Ͱ ݁߹ɾิ׬
  4. LJOUPOFΤίγεςϜʢԦಓͬΆ͍"84ͱLJOUPOFͷ࿈ܞύλʔϯʣ 10 "NB[PO%ZOBNP%# 4USFBN "NB[PO4/4 "NB[PO4 "NB[PO,JOFTJT "84-BNCEB "NB[PO&$ -BNCEB

    Πϕϯτιʔε 3&45"1* LJOUPOFPODZCP[VDPN ɾϨίʔυૢ࡞ ɾϫʔΫϑϩʔૢ࡞ ɾεϖʔεૢ࡞ ɾΞϓϦૢ࡞ 3&45"1* LJOUPOFQSPYZ  "NB[PO"1*(BUFXBZܦ༝͸ྑͦ͞͏ɾɾɾ 3 &45" 1* ϓϦϛςΟϒͳ࿈ܞ ɾϗεςΟϯά ɾόονॲཧ "84*P5 "NB[PO "1*(BUFXBZ
  5. LJOUPOFΤίγεςϜʢLJOUPOFͱ"84αʔόϨεΞʔΩςΫνϟʣ 11 "NB[PO%ZOBNP%# 4USFBN "NB[PO4/4 "NB[PO4 "NB[PO,JOFTJT "84-BNCEB "NB[PO&$ -BNCEB

    Πϕϯτιʔε 3&45"1* LJOUPOFPODZCP[VDPN 3&45"1* LJOUPOFQSPYZ  "NB[PO"1*(BUFXBZܦ༝͸ྑͦ͞͏ɾɾɾ 3 &45" 1* ϓϦϛςΟϒͳ࿈ܞ ɾϗεςΟϯά ɾόονॲཧ "84*P5 "NB[PO "1*(BUFXBZ ɾϨίʔυૢ࡞ ɾϫʔΫϑϩʔૢ࡞ ɾεϖʔεૢ࡞ ɾΞϓϦૢ࡞ -BNCEBͷ ར༻͕ݤʂ
  6. τϦΨʔ αʔόϨεʢ-BNCEBʣʹΑΔॲཧܥͷྫ 15 σʔλ ɾϩʔυόϥϯε ɾϨϓϦέʔγϣϯ ɾΦʔτεέʔϧ ॲཧʢίʔυʣͷ ࣮ߦ σʔλͷൃੜ͕

    τϦΨʔͱͯ͠౉Δ w Πϯϑϥߏஙෆཁ w Πϯϑϥͷӡ༻؅ཧෆཁ w ΩϟύγςΟ w εέʔϧ w σϓϩΠ w ো֐଱ੑ w ϞχλϦϯά w ϩΪϯά w ηΩϡϦςΟύονద༻ αʔόϨεʢ-BNCEBʣͷԸܙ
  7. w ΞϓϦ։ൃʹଟ͘ͷϝϦοτ w όοΫΤϯυଆͷίʔυ͕ݮΔͨΊ։ൃίετΛ࠷খԽ w όοΫΤϯυଆͷαʔό͕ݮΔͨΊӡ༻ίετΛ࠷খԽ w "84ʹΑͬͯϚωʔδ͞ΕΔͨΊɺεέʔϥϏϦςΟ΍ΩϟύγςΟɺηΩϡϦςΟͷ৺഑ෆཁ w ඇৗʹίετޮ཰͕ߴ͍ͨΊɺଟ͘ͷ৔߹ɺίετݮ͕ݟࠐΊΔ

    w ඞཁʹԠͯ͡&$΋ಋೖͰ͖Δ҆৺ײ w ൚༻తͳαʔϏεͰ͸࣮ݱͷ೉͍͠Ϗδωεݻ༗ͷཁ݅ʹؔͯ͠͸&$Λར༻࣮ͯ͠૷ w &$Λར༻͢Δ෦෼ʹ͍ͭͯ΋$PEF%FQMPZ΍&MBTUJD#FBOTUBMLɺ0QT8PSLT౳ͰࣗಈԽ w ։ൃऀ͕ϏδωεʹϑΥʔΧεͰ͖Δ αʔόϨεΞʔΩςΫνϟͷԸܙ 17
  8. w "NB[PO4 w "NB[PO,JOFTJT4USFBNT w "NB[PO%ZOBNP%# 4USFBNT w "NB[PO$PHOJUP w

    "NB[PO4/4 w "MFYB"QQ,JU w "NB[PO48' w "NB[PO4&4JOCPVOENBJM w "NB[PO$MPVE8BUDI-PHT w "NB[PO$POOFDUFE)PNF w "84*P5 w 4DIFEVMF&WFOU "84-BNCEBʢଓ͖ʣ 20 Πϕϯτιʔε τϦΨʔ /PEFKT 1ZUIPO +BWB -BNCEBؔ਺ͷىಈ ͷίʔυΛ࣮ߦ ࠷େ෼ؒͷλΠϜΞ΢τ
  9. w &$ʹ࡞ΓࠐΈ͠ͳͯ͘΋༰қ ʹ"1*͕࡞ΕΔ w ΤϯυϙΠϯτͷ׬શެ։΍ "1*Ωʔ౳ΞΫηεɾೝূϨϕ ϧΛॊೈʹઃఆͰ͖Δ w $034ઃఆʹରԠ w

    "1*ͷόʔδϣϯ؅ཧ͕Ͱ͖Δ "NB[PO"1*(BUFXBZ 21 ΤίγεςϜܗ੒ɾγεςϜؒ࿈ܞΛՄೳʹ͢Δ"1*ͦͷ΋ͷ Λ༰қʹ࡞ΕΔͷͰɺΤίγεςϜܗ੒ͷෑډ͕ߋʹԼ͕Δʂ
  10. -BNCEBؔ਺ͷॻ͖ํ 37 /PEFKT exports.handler = function(event, context) { // ਖ਼ৗͱͯ͠ऴ͍ྃͤͨ࣌͞ʹ͸

    context.succeed(); // ҟৗͱͯ͠ऴ͍ྃͤͨ࣌͞ʹ͸ context.fail(); }; DPOUFYUTVDDFFEGBJMͷهड़Λ๨ΕΔ ͱΤϥʔͷݪҼʹ΋ͳΔͷͰ஫ҙ 1ZUIPO def lambda_handler(event, context): # ऴ͍ྃͤͨ࣌͞ʹ͸ return event['requestParameters'] # ྫ֎ॲཧ͢Δ࣌ʹ͸ raise Exception('Something went wrong')
  11. LJOUPOF#BDLMPH࿈ܞʢ"1*(BUFXBZͷઃఆɿࠓճͷ.BQQJOH5FNQMBUFʣ 73 w ϦΫΤετύϥϝʔλͷऔಘ w 1045165͸JOQVUKTPO   w (&5͸JOQVUQBSBNT

    RVFSZTUSJOH w ύε΍ϔομͷ஋΋औಘՄ w ৄࡉ͸ʮ.BQQJOH5FNQMBUF 3FGFSFODFʯΛ֬ೝ -BNCEBͷFWFOU΁౉Δύϥϝʔλͷઃఆ
  12. LJOUPOF#BDLMPH࿈ܞʢ"1*(BUFXBZͷઃఆɿࠓճͷ.BQQJOH5FNQMBUFʣ 74 w ϦΫΤετύϥϝʔλͷऔಘ w 1045165͸JOQVUKTPO   w (&5͸JOQVUQBSBNT

    RVFSZTUSJOH w ύε΍ϔομͷ஋΋औಘՄ w ৄࡉ͸ʮ.BQQJOH5FNQMBUF 3FGFSFODFʯΛ֬ೝ -BNCEBͷFWFOU΁౉Δύϥϝʔλͷઃఆ ࠓճ͸1045ͷύϥϝʔλ Λड͚औΔͷͰͪ͜Β
  13. ʲࢀߟʳLJOUPOF3&45"1*ͷ֓ཁ 98 w LJOUPOFΞϓϦͷϨίʔυ΍εϖʔεͷૢ࡞ LJOUPOF3&45"1*ͷ༻్ ϓϩτίϧ w )5514ϓϩτίϧ ϑΥʔϚοτ w

    +40/ จࣈίʔυ w 65' ೝূೝূ w Ϣʔβೝূʢύεϫʔυɺ"1*τʔΫϯʣ w #BTJDೝূ ͦͷଞ w ಉ࣌ॲཧϨίʔυ਺݅ w "1*ಉ࣌ΞΫηε݅ ˞(&5SFDPSETͷΈ݅
  14. ʲࢀߟʳϦΫΤετྫʢ(&5SFDPSETʣ 100 QWRtaW5pc3RyYXRvcjpwYXNzd29y (&5ϝιουͰ͸ $POUFOU5ZQF͸ෆཁ #BTJDೝূΛ࢖༻͍ͯ͠ͳ͍৔߹ʹ΋ ۭཝͰೖΕ͓ͯ͘෼ʹ͸໰୊ͳ͍༷ࢠ https://{subdomain}.cybozu.com/k/v1/records.json?app={app id} ɹʲೝূํ๏ͷهड़ʳ

    9$ZCP[V"VUIPSJ[BUJPO\#"4&FODPEFEJEQBTTXPSE^ "VUIPSJ[BUJ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