Serverless Architecture

B4afc7d853d7f1cb6a253d3c7183c05a?s=47 Naoya Ito
October 24, 2016

Serverless Architecture

補足: AWS Lambda のコンテナのライフサイクルについては説明を単純化していますので、詳しくは http://www.slideshare.net/keisuke69/aws-lambda-46129981 こちらの 42 ページ以降を参照してください

B4afc7d853d7f1cb6a253d3c7183c05a?s=128

Naoya Ito

October 24, 2016
Tweet

Transcript

  1. 2.

    ઌʹ݁࿦ •  αʔόʔϨεΞʔΩςΫνϟͱ͸ –  ୯७ʹ͸'BB4Λ࢖ͬͨγεςϜ –  εςʔτϨεͳ'BB4͕ϦΞΫςΟϒɺ.JDSPTFSWJDFTɺίϨΦάϥ ϑΟ΁ͱಋ͘ •  ݱ৔ײ֮Ͱ͸ʮӡ༻ָ͕Ͱεέʔϧͯ͠ɺ͍҆ʯ

    •  ۜͷ஄ؙͰ͸ͳ͍͕ɺԠ༻ྖҬ͸֦͕ΔͱࢥΘΕΔ •  ͪΐͬͱͨ͠λεΫΛ͜ͳͨ͢Ί΍ɺ.JDSPTFSWJDFTͷ࣮ݱखஈͱ ͯ͠ɺҾ͖ग़͠ͷҰͭʹೖΕ͓͍ͯͯଛ͸ͳ͍
  2. 3.

    ඞཁʹͳͬͨ ͱ͖͚ͩܭࢉ Πϕϯτۦಈ .JDSPTFSWJDFT 3FBDUJWF ΦʔέετϨʔ γϣϯ͔ΒίϨ ΦάϥϑΟ΁ αʔόʔϨε 4IBSFE

    /PUIJOH ӡ༻ෛ୲͕গͳ͍ ͍҆ εέʔϥϒϧ ಘΒΕΔϝϦοτ ΞʔΩςΫνϟͷੑ࣭
  3. 7.

    "84-BNCEB •  "84্Ͱɺ೚ҙͷখ͞ͳؔ਺Λ࣮ߦ͢ΔͨΊͷαʔϏε –  1ZUIPOɺ/PEFKTɺ+BWBͳͲͰॻ͍ͨؔ਺ΛΞοϓϩʔυ –  ೚ҙͷΠϕϯτΛܖػʹɺͦͷؔ਺Λ࣮ߦͰ͖Δ –  Πϕϯτྫ • 

    )551ϦΫΤετΛड৴ͨ͠ •  4ʹϑΝΠϧ͕Ξοϓϩʔυ͞Εͨ •  ,JOFTJTͷετϦʔϜͷΠϕϯτ͕ൃੜͨ͠ •  "NB[PO4JNQMF&NBJMʹϝʔϧ͕ಧ͍ͨ •  %ZOBNP%#ʹ৽͍͠ΞΠςϜ͕*/4&35͞Εͨ •  4DIFEVMFE&WFOUT CZ$MPVE8BUDI  •  ŋŋŋ
  4. 8.

    module.exports.hello = (event, context) => { context.succeed({ message: 'Hello, '

    + event.query.username }) } # Serverless Framework を利用 $ serverless deploy
  5. 10.

    -BNCEBϑΝϯΫγϣϯ͸εςʔτϨεͰ͋Δ •  ίϯςφ͸࣮ߦ࣌ʹͷΈଘࡏɻঢ়ଶ εςʔτ Λอ࣋Ͱ͖ͳ͍ •  εςʔτϨε 4IBSFE/PUIJOH  – 

    Կ͔໰୊͕ىͬͯ͜΋ɺผͷ࣮ߦʹ͸ѱӨڹΛ༩͑ͳ͍ –  εέʔϧ͔ͨͬͨ͠Β΋ͬͱىಈ͢Ε͹Α͍
  6. 11.

    "84-NCEB͸εέʔϧ͢Δ͠ɺ͍҆ •  Πϕϯτྔʹ߹Θͤͯ-BNCEB͕ࣗಈͰεέʔϧ –  εςʔτϨεͳͷͰ ఏڙऀͰ͋Δ"84తʹ΋ εέʔϧ͠΍͍͢ –  ؾ͍ͮͨΒ/PEFϓϩηεམͪͯͨŋŋŋͳͲ͕ͳ͍ɻ҆શ 

    •  ܭࢉͨ͠෼͔͠අ༻͸͔͔Βͳ͍ –  "NB[PO&$ŋŋŋΠϯελϯε͕ىಈͨ࣌ؒ͠෼ͷඅ༻ –  "84-BNCEBŋŋŋ࣮ߦͨ͠෼ͷΈͷඅ༻ ͔ͳΓ͓ಘ
  7. 13.
  8. 16.

    -BNCEBؔ਺͸Πϕϯτۦಈ AWS Lambda S3 bucket Πϕϯτ "Records": [ { "eventVersion":

    "2.0", "eventTime": "1970-01-01T00:00:00.000Z", "requestParameters": { "sourceIPAddress": "127.0.0.1" }, "s3": { "configurationId": "testConfigRule", "object": { "eTag": "0123456789abcdef0123456789abcdef", "sequencer": "0A1B2C3D4E5F678901", "key": "HappyFace.jpg", "size": 1024 }, "bucket": { "arn": bucketarn, "name": "sourcebucket", "ownerIdentity": { "principalId": "EXAMPLE" } }, },   ...
  9. 19.

    )551ϦΫΤετ΋ΠϕϯτʹͳΔ AWS Lambda Amazon API Gateway 8FCIPPL )551  Πϕϯτ

    { "body": {}, "method": "GET", "headers": { "Accept": "*/*", "CloudFront-Forwarded-Proto": "https", "CloudFront-Is-Desktop-Viewer": "true", "CloudFront-Is-Tablet-Viewer": "false", "CloudFront-Viewer-Country": "JP", "User-Agent": "curl/7.43.0", "Via": "1.1 2d30d2b55574343a43311dd210926843.cloudfront.net (CloudFront)", "X-Amz-Cf-Id": "JDBHHrMHhbxwaMfNBBTo15EICVfU8t6JHTExkGpu2W6_O4h5wBtqsg==", "X-Forwarded-Port": "443", "X-Forwarded-Proto": "https" }, "query": { "user": "naoya", "foo": "bar" }, "path": {}, "identity": { "accessKey": "", "cognitoAuthenticationType": "", "cognitoAuthenticationProvider": "", "userAgent": "curl/7.43.0", } }
  10. 26.

    ඞཁʹͳͬͨ ͱ͖͚ͩܭࢉ Πϕϯτۦಈ .JDSPTFSWJDFT 3FBDUJWF ΦʔέετϨʔ γϣϯ͔ΒίϨ ΦάϥϑΟ΁ αʔόʔϨε 4IBSFE

    /PUIJOH ӡ༻ෛ୲͕গͳ͍ ͍҆ εέʔϥϒϧ ಘΒΕΔϝϦοτ ΞʔΩςΫνϟͷੑ࣭
  11. 29.

    QSFGPSL͸Φʔόʔϔου͸গͳ҆͘શ͕ͩɺฒߦੑೳʹ೉ •  ྫ –  ΞϓϦέʔγϣϯαʔόʔ ྫ'BTU$(*ɺ1VNBɺ+FUUZɺ**4  •  1SPT – 

    ϦΫΤετຖGPSL ͷΦʔόʔϔουΛճආͰ͖Δ –  ଟ͘͸ڞ༗͠ͳ͍ͷͰɺൺֱత҆શ •  $POT –  εέʔϥϏϦςΟʹ೉ •  ϝϞϦϑοτϓϦϯτ͕େ͖͍ɻϓϩηε਺͕࠷େಉ࣌઀ଓ਺ $,໰୊  •  ߴෛՙͰ͸ϓϩηεεϨουͷίϯςΩετεΠονίετ͕ߴ͍
  12. 31.

    ΠϕϯτۦಈϞσϧ͸ฒߦੑೳ͕ߴ͍͕Մ༻ੑʹ೉ •  ྫ –  /PEFKT •  1SPT –  εέʔϥϏϦςΟ • 

    ϝϞϦϑοτϓϦϯτ͕খ͘͞ɺߴ͍ฒߦॲཧੑೳ •  $POT –  Մ༻ੑ ଱ো֐ੑ ʹ೉ •  མͪΔͱ͖͸શ෦མͪΔϝϞϦϦʔΫ࣌ͷϦεΫ͕େ͖͍
  13. 37.
  14. 38.
  15. 39.
  16. 40.
  17. 47.

    ΦʔέετϨʔγϣϯWTίϨΦάϥϑΟ 40"΍#1.ɺ.JDSPTFSWJDFTͷจ຺ͰϏδωεϓϩηεߏஙͷͨΊʹ αʔϏεؒΛͲ͏͍͏ΞʔΩςΫνϟͰؔ࿈͚ͮΔ͔ͷٞ࿦  •  ΦʔέετϨʔγϣϯ PSDIFTUSBUJPO  –  ΦʔέετϥʹΑΔԋ૗ํ๏

    –  தԝͷࢦشऀ͕αʔϏεͷݺͼग़͠Λίϯτϩʔϧ͠ɺϏδωεϓϩηε ͷ࣮ߦΛࢦش͢Δ  •  ίϨΦάϥϑΟ DIPSFPHSBQIZ  –  όϨʔ΍෣౿ͳͲͷμϯαʔ΁ͷৼΓ෇͚ –  αʔϏεͷݺͼग़͠Λίϯτϩʔϧͨ͠ΓɺϏδωεϓϩηεͷ࣮ߦΛࢦ ش͢Δଘࡏ͸͍ͳ͍ 
  18. 51.

    ίϨΦάϥϑΟ͸ૄ݁߹Ͱεέʔϥϒϧ •  ҰൠʹɺίϨΦάϥϑΟख๏ʹ޲͔͏܏޲͕ڧ͍γεςϜͷํ͕ɺ ૄ݁߹Ͱॊೈੑ͕͋ΓɺมߋΛड͚ೖΕΔ͜ͱ͕Θ͔͍ͬͯ· ͢ɻ ʮϚΠΫϩαʔϏεΞʔΩςΫνϟʯ ΦϥΠϦʔɾδϟύϯ 1  

    •  ҰํɺίϨΦάϥϑΟ͕ৗʹਖ਼ղͰ͸ͳ͍ –  ಉظݺͼग़͠ͷํ͕୯७ɺద੾ʹػೳ͍ͯ͠Δ͔͕Θ͔Γ΍͍͢  •  .JDSPTFSWJDFTΛࢦ޲͢ΔͳΒίϨΦάϥϑΟ –  ඇಉظͷΠϕϯτ࿈ܞŋŋŋେ෯ʹ෼཭͞ΕͨαʔϏεΛੜΈग़ͤΔ
  19. 53.

    ඞཁʹͳͬͨ ͱ͖͚ͩܭࢉ Πϕϯτۦಈ .JDSPTFSWJDFT 3FBDUJWF ΦʔέετϨʔ γϣϯ͔ΒίϨ ΦάϥϑΟ΁ αʔόʔϨε 4IBSFE

    /PUIJOH ӡ༻ෛ୲͕গͳ͍ ͍҆ εέʔϥϒϧ ಘΒΕΔϝϦοτ ΞʔΩςΫνϟͷੑ࣭
  20. 56.
  21. 58.

    ͿͬͪΌ͚Ͳ͏ͳͷ  •  ͸·Ε͹ڧ͍ –  εέʔϥϒϧɻӡ༻޻਺͸͍͢͝Լ͕Δɻ&$ΑΓ௒͍҆ –  ஌ΒΜ͏ͪʹྑ͍ΞʔΩςΫνϟʹ޲͔ͬͯͨΓ͢Δ •  ؔ਺͕খ͘͞·ͱ·ͬͨΓɺςελϏϦςΟߴ͔ͬͨΓ

    •  ։ൃ޻਺͸ͦ͜·Ͱ࡟ݮ͞Εͳ͍͔΋ –  'BB4ಛ༗ͷ όουͳ΋ͷ΋ؚΉ ϊ΢ϋ΢͕ඞཁ •  Πϕϯτ͕ϧʔϓͯ͠αϜωΠϧͷαϜωΠϧͷαϜŋŋŋˠ㱣ͱ͔͋Δ͋Δ •  ಉظॲཧ͍ͨ͠ͳঢ়ଶ͍࣋ͪͨͳͱ͍͏ͱ͖೰Ή •  ϓϩάϥϜαΠζʹ੍ݶ͕͋ͬͨΓ͢Δ –  ϐλΰϥεΠονʹͳΔͷͰσόοά͕େมɻ݁߹ςετ೉͍͠
  22. 60.

    Ͳ͏͍͏ͱ͖࢖͏ͷ  •  খ͞ͳϢʔεέʔεͰ͸ੵۃతʹ࢖͑͹͍͍ –  αϜωΠϧ࡞Δ͚ͩɺͱ͔ɺ4MBDL௨஌ͱ͔ •  େ͖ͳϢʔεέʔεͰ͸͍ͭ࢖͏ͷ͔ŋŋŋ·ͩݴޠԽͰ͖ͯͳ͍ –  ʮۜͷ஄ؙͰ͸ͳ͍ʯͱ͸ΈΜͳݴ͏ɻʮ͜͜Ͱ࢖͑ʂʯͱ͸ݴΘͳ͍

    –  Φʔόʔϔου͸ൺֱతখ͍͕͞θϩͰ͸ͳ͍ –  ίϨΦάϥϑΟͰ0,ͳΒɺͱ͍͏ͷ͸͋Γͦ͏  •  αʔόʔϨεͱͦ͏͡Όͳ͍ͷΛ૊Έ߹ΘͤΔࣄྫ͕૿͑ͯΔ –  ྫػցֶशͷϞσϧߏங͸ී௨ʹ΍ͬͯɺͦΕΛར༻͢ΔΞϓϦέʔγϣ ϯ͸αʔόʔϨε
  23. 61.

    αʔόʔϨεͷࠓޙ •  ΞʔΩςΫνϟతʹਅͬ౰ͩ͠ɺద༻ൣғ͸֦͕Δͱࢥ͏ –  ಛʹϦΞϧλΠϜͳεέʔϥϏϦςΟ͕ཉ͍͠έʔε •  ήʔϜαʔόʔɺߦಈϩάऩूɺ*P5ŋŋŋ –  Ͳ͏͍͏ͱ͖αʔόʔϨε͕͍͍͔ͷٞ࿦͸͜Ε͔Β੒ख़͍ͯ͘͠Ͱ͠ΐ͏ – 

    ઃܭํ๏ͷҾ͖ग़͠ͷҰͭʹՃ͓͍͑ͯͯଛ͸ͳ͍  •  ։ൃ؀ڥ ϑϨʔϜϫʔΫ ͸΋͏Ұ੠ཉ͍͠ɻྑ͍΋ͷ͸ࠓޙ΋ग़͖ͯͦ͏ –  4FSWFSMFTT͕಄Ұͭग़ͯΔ͕ɺ·ͩσϓϩΠࣗಈԽϨϕϧ •  ޚࡾՈͷ։ൃڝ૪͕੝ΜʹɻߴػೳԽɺੑೳ޲্͸ਐΉ –  "84WT($1WT"[VSF –  Φʔόʔϔου͸ٕज़ֵ৽ͰͲΜͲΜখ͘͞ͳΔͱࢥΘΕΔ
  24. 62.

    ·ͱΊ •  αʔόʔϨεΞʔΩςΫνϟͱ͸ –  ୯७ʹ͸'BB4Λ࢖ͬͨγεςϜ –  εςʔτϨεͳ'BB4͕ϦΞΫςΟϒɺ.JDSPTFSWJDFTɺίϨΦάϥ ϑΟ΁ͱಋ͘ •  ݱ৔ײ֮Ͱ͸ʮӡ༻ָ͕Ͱεέʔϧͯ͠ɺ͍҆ʯ

    •  ۜͷ஄ؙͰ͸ͳ͍͕ɺԠ༻ྖҬ͸֦͕ΔͱࢥΘΕΔ •  ͪΐͬͱͨ͠λεΫΛ͜ͳͨ͢Ί΍ɺ.JDSPTFSWJDFTͷ࣮ݱखஈͱ ͯ͠ɺҾ͖ग़͠ͷҰͭʹೖΕ͓͍ͯͯଛ͸ͳ͍
  25. 63.

    ࢀߟจݙ 8FC  •  αʔόϨεͱϚΠΫϩαʔϏεͰมΘΔήʔϜαʔό։ൃ –  IUUQTTQFBLFSEFDLDPNLB[VUPNPTBIBSFTVUPNBJLVSPTBIJTVUFCJBOXBSVLFNVTBIBLBJGB •  ࢴ໘ϏϡʔϫʔΛࢧ͑ΔαʔόʔϨεΞʔΩςΫνϟ – 

    IUUQTTQFBLFSEFDLDPNJLBJUTFSWFSMFTTBSDIJUFDUVSFTVQQPSUTOJLLFJTQBQFSWJFXFS •  #VJMEJOH&WFOUESJWFO4FSWFSMFTT"QQT –  IUUQXXXTMJEFTIBSFOFUEBOJMPQCVJMEJOHFWFOUESJWFOTFSWFSMFTTBQQT •  "84-BNCEBJO"DUJPO&WFOU%SJWFO4FSWFSMFTT"QQMJDBUJPOT –  IUUQTFWFOUESJWFOBQQTDPN •  5ZQFTBGF3FBDUJWF1MBUGPSNͰ࡞Δ3FBDUJWF4ZTUFN –  IUUQXXXTMJEFTIBSFOFUZVHPMGUZQFTBGFSFBDUJWFQMBUGPSNSFBDUJWFTZTUFNTDBMBTVNNJULBOTBJ •  ίϨΦάϥϑΟWTΦʔέετϨʔγϣϯ –  IUUQXXXpPSBOPDPNKQCMPHJOUFHSBUJPOJOUFHSBUJPOBSDIJUFDUVSFίϨΦάϥϑΟWTΦʔέετϨʔγϣ ϯ •  ελʔόοΫε͸ϑΣʔζίϛοτΛ࢖Θͳ͍ –  IUUQTDPEFHPPHMFDPNBSDIJWFQHSFHPSTSBNCMJOHTKBXJLJT@TUBSCVDLTXJLJ