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

サーバレスアーキテクチャはじめの一歩

 サーバレスアーキテクチャはじめの一歩

Koji Nakayama

April 22, 2017
Tweet

More Decks by Koji Nakayama

Other Decks in Technology

Transcript

  1. ᛔ૩奧Օ • Ӿઊ ଛလ • μ϶φϮϊϐϖ AWSԪ䮣᮱ ϊϷϲЄτϴ ЀίЄκϓμϕ •

    AWSΨڥአͭ͵αЀϢ϶΄戔懯/䯤塈/π ЀςϸϓΰЀν • GitHub: knakayama • 奺䵉 • ηЀϤϹςЄϝ΄晁አ3ଙ • AWS 1ଙ 2
  2. 7

  3. Serverless;΅֜͡ • Ӟᛱጱ΁΅Function as a Service(FaaS)ΨӾஞ;ͭ͵ίЄκϓμώϰ • AWSͽ΅Lambda • ͵Ͷ̵ͭLambdaͯΟֵΥ΀͚ίЄκϓμώϰΨͩ͜޷Ό䁰ݳΘ͘Ρ

    (Lambdaless) • ͩ΄旽΅ۆ;䨀ซ • αϦЀϕϖϷϣЀ;͚͜ᇙ䖀͘͢Ρ • ֜Ο͡΄αϦЀϕΨॶ䱛;ͭͼϡόρ϶φαϐώጱ΁ݱ圵㳌ቘ͢䋚ᤈͫ΢Ρ 16
  4. Lambda • πЄϖΨ䋚ᤈͽͣΡπЀϡϲЄϓΰЀνςЄϠφ • ςЄϝΚϤϺψφΨ樄咲ᘏ㯎ͽᓕቘͯΡ஠ᥝ͢΀͚ • Ϸμεφϕ/䋚ᤈ䦒樌΁䖕ͮ͵䕪ᰁ抓ᰂګ • ਞ͚ •

    僻ාڥአ䩵Θ꧌䋚 • EC2΄䁰ݳ๋֗1䦒樌㶨֖ͽ抓ᰂ • 匍䦒ᅩͽلୗςϪЄϕͭͼ͚Ρ᥺承΅Node.js/Python/Java/C# • ͵Ͷͭ㳨΄᥺承Θ䋚ᤈݢᚆ 17
  5. S3 Event Notification • S3΁咲ኞͭ͵αϦЀϕ(Put/Delete΀Ϳ) Ψॶ䱛΁ݱ圵㳌ቘΨ䋚ᤈͽͣΡ՛奲Ε 1. ᓕቘᘏ͢ίϐϤϺЄϖአϝξϐϕ΁ኮ ؟ΨPut 2.

    S3 Event NotificationͽLambda᩸㵕 3. Lambdaͽኮ؟Ψےૡ̵ͭᤒᐏአϝξϐ ϕ΁Put 4. ϳЄσ΅CloudFront奺ኧͽኮ؟Ψᤒᐏ 19
  6. SNS Notification • SNSϕϡϐμ奺ኧͽLambda᩸㵕ݢᚆ 1. ͚ͭͣ㮔Ψ᩻晃ͭ͵΄ͽCloudWatch Alarm咲ᅉ 2. CloudWatch Alarm΄ίμτϴЀͽSNS

    ϕϡϐμ΁᭗Ꭳ 3. ϕϡϐμΨςϣφμ϶αϣͭͼ͚Ρ LambdaΨ䋚ᤈ 4. Lambda͡ΟSlack΁᭗Ꭳ 20
  7. Kinesis Firehose • Kinesis Firehose΄φϕϷЄϭॶ䱛ͽ Lambda᩸㵕ݢᚆ 1. ϤϺϔϲЄς͡ΟKinesis Firehose΁φ ϕϷЄϭϔЄόಭف

    2. φϕϷЄϭϔЄό͢ಭفͫ΢Ρ; Lambda᩸͢㵕ͫ΢ͼETL㳌ቘ䋚ෞ 3. ๋奰ጱ΁ےૡͫ΢͵ϔЄόΨS3΁Put 21
  8. 24

  9. Serverless΀ίЄκϓμώϰ • CloudFrontͽϞφϦЄφϸЄϓΰЀν • Ϟφ΁䖕ͮͼS3͡API Gateway΁ϕ϶ Ϣΰϐμၞͯ • S3΄WebϨφϓΰЀνͽUIᤒᐏ •

    API Gateway΄IntegrationͽLambda᩸㵕 • Lambda͡ΟDynamoDB΁put_item/ get_item • ϔЄόφϕί;ͭͼDynamoDB • Lambda on VPC + RDSͽΘOK 25
  10. ServerlessίЄκϓμώϰ΄抓氂 • LambdaΨ㵕֢ͫͱΡ΄΅఺क़;ᶎׯ͚ͥͫ • ϫϚυϮЀϕπЀϊЄϸͽፗളπЄϖ䨗ͥ • ϺЄθϸͽπЄϖ䨗ͥ → Zip΁ࢴΗΡ →

    ίϐϤϺЄϖͯΡ • LambdaӞ㮆Ͷͧͽਠ奾ͯΡΞ͜΀䯤౮΅ΑΒ΀͚ • 愢හ΄AWSϷϊЄφΨڥአͯΡ΄͢୮͵Πڹ • ϓφϕΨͭ͵͚ • ϳϘϐϕϓφϕ • ϺЄθϸ厏हͽ΄ϓφϕ • ͩ΄旽ΨӤಋͥΚ͹ͼͥ΢Ρ՛奲Ε͢Α͚ͭ 28
  11. ϢϹЄϭϼЄμ • ϔϤϺαϮЀϕϞϐξЄυ֢౮ϤϺψφ΄墋ᔰ۸ • ServerlessίЄκϓμώϰق֛΄πЄϖ۸ • CloudFormation • Terraform •

    πЄϖ۸΁ΞΡڥᅩ • ٚ匍௔ • Git/GitHub/PR洑㵕樄咲 • CI/CDΨڥአͭ͵ϔϤϺαϞαϤ϶αЀ۸ 30
  12. դᤒጱ΀ϢϹЄϭϼЄμ Serverless Framework AWS Serverless Application Model(AWS SAM) Apex 䋚ᤰ

    Node.js ᎣΟΩ(Java?) Go ϫϸώμ϶γϖ Yes No No OSS Yes No Yes AWSϷϊЄφ΄֢౮ොဩ CloudFormation(Ӟ᮱ᶋ䌏䖕) CloudFormation Terraform CLI΄ํ僻 Yes(sls) No(AWS CLI?) Yes(apex) ͳ΄՜ Ϥ϶ναЀ΁ΞΡ䝭䔴 ϺЄθϸ䋚ᤈ΄ςϪЄϕ ग़䱛ᚆ ڥአᘏग़͚Ҙ AWS挘愚 Swagger & ChangeSetςϪЄϕ 㷗ੂ΁᥺͜;ϢϹЄϭϼЄμ ͽ΅΀ͥϯϔϸ HookςϪЄϕ Go᥺承΄ςϪЄϕܹ͚Ҙ Dry-runςϪЄϕ τЀϤϸ 31
  13. ϳϘϐϕϓφϕ • Lambda΅क़᮱͡ΟჁͫ΢͵ϔЄόΨ㳌ቘͯΡ樛හ;഍͞Ρͩ;ΘͽͣΡ • AWS΄䁰ݳLambda΁Ⴡͫ΢ΡϔЄό΅㶨΀ΡJSON • ෬ਂϓφϕϯυϲЄϸΨֵ͹͵ϳϘϐϕϓφϕ͢ݢᚆ • ᇙਧ΄JSONΨჁͯ →

    奾ຎ͢๗இͭ͵Θ΄͡嘦扯 • Node.js΄chai;͡ΞֵͥΥ΢ͼΡ͹Γ͚ • http://qiita.com/horike37/items/15bf675f973d30bb1f5c • PythonͶ͹͵Οpytest • https://librabuch.jp/blog/2016/07/aws-lambda-environment/ 33
  14. ϺЄθϸ厏हͽ΄ϓφϕ • ϓφϕΨͯΡ΄΁AWS厏हΨ͚ͷ͚ͷአ఺ͯΡ΄΅ᶎׯ • ϺЄθϸͽAWS;ݶᒵ΄䱛ᚆΨͯΡΘ΄Κ̵ϯϐμᔮ΄ϑЄϸΨڥአͯΡ ϑЄϸ ༷ᥝ Serverless Framework lambda-local

    Lambda΄فڊێΨϺЄθϸͽٚ匍ݢᚆ DynamoDB Local DynamoDB;ݶᒵ΄䱛ᚆΨϺЄθϸͽٚ匍ݢᚆ AWS挘愚 mhart/kinesalite Kinesis΄فڊێΨϺЄθϸͽٚ匍ݢᚆ spulec/moto AWSςЄϠφ΄فڊێΨϺЄθϸͽٚ匍ݢᚆ atlassian/localstack 愢හ΄ϺЄθϸ䋚ᤈᔮςЄϠφΨΔ;Η͵ϢϸφόϐμϑЄϸ 34
  15. ᐒտ΅ኚͥ΀͚ • Lambda΁΅ͳ΢΀Π΁ګ夹͘͢Ρ • ๋य़䋚ᤈ䦒樌5ړ • ๋य़φϕϹЄυ512MB(/tmp) • ෬ਂ΄ದ悬;ϫϐώͭ΀͚䁰ݳΘ͘Ρ •

    Ruby on Rails;͡ • قͼ΄EC2Ψᗝͣ䟵͞ΡΘ΄ͽ΅΀͚ • 䁰ݳ΁Ξ͹ͼπЀϓϗ(ECS)ςЄϠφΘ䭥懵ͯΡ • 晒๭晒ಅͽڥአͯΡͩ; 36
  16. Serverless͢ϜϫΠΚ͚ͯϳЄφξЄφ • ϷίϸόαϭϢήαϸ㳌ቘ • S3΄Event NotificationͽLambda᩸㵕 → ኮ؟㳌ቘ • ϷίϸόαϭφϕϷЄϭ㳌ቘ

    • Kinesis → LambdaͽETL → S3ΚDynamoDB • APIϝϐμεЀϖ • API Gateway;΄Integration → Lambda → ϔЄόφϕί • SNSϕϡϐμ;΄昧൭ • AWSςЄϠφ樌΄Ϝϣ;΀ΡSNSϕϡϐμ → Lambda᩸㵕 → ձ఺΄㳌ቘ https://www.slideshare.net/keisuke69/aws-lambda-amazon-api-gateway-deep-dive 37