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

実践サーバレス + α / Serverless Practices

Masashi Terui
November 17, 2018

実践サーバレス + α / Serverless Practices

We wanna Tech@青森
https://connpass.com/event/103101/

Masashi Terui

November 17, 2018
Tweet

More Decks by Masashi Terui

Other Decks in Technology

Transcript

  1. SERVERWORKS CO.,LTD. + FREELANCER • Serverless Oji-san • Serverlessconf Tokyo

    2016,2017,2018 speaker • Remote worker (in Sapporo) • @marcy_terui • https://willy.works MASASHI TERUI ARCHITECT / DEVELOPER
  2. AGENDA SERVERLESS ͬͯͳΜ͚ͩͬʁ 1 6 2 7 3 8 4

    9 5 10 SERVERLESS ͷ࣮ମΛଊ͑Δ SERVERLESS ͷઃܭ SERVERLESS ͷ࣮૷ SERVERLESS ͷσϓϩΠ SERVERLESS ͷӡ༻ SERVERLESS ͷݱ࣮ SERVERLESS ͷະདྷ SERVERLESS ͷ͓·͚ SERVERLESS ͷςετ
  3. CNCF SERVERLESS WHITEPAPER V1.0 • Serverless computing refers to the

    concept of building and running applications that do not require server management • A platform may provide one or both of the following: • Functions-as-a-Service (FaaS) • Backend-as-a-Service (BaaS) • Products or platforms deliver the following benefits to developers: • Zero Server Ops • No Compute Cost When Idle 
 https://github.com/cncf/wg-serverless/tree/master/whitepaper
  4. SERVERLESS USE CASES (FROM CNCF WP) • Asynchronous, concurrent, easy

    to parallelize into independent units of work • Infrequent or has sporadic demand, with large, unpredictable variance in scaling requirements • Stateless, ephemeral, without a major need for instantaneous cold start time • Highly dynamic in terms of changing business requirements that drive a need for accelerated developer velocity • Non-HTTP-centric and non-elastic scale workloads that weren’t good fits for an IaaS, PaaS, or CaaS solution (Event Driven workloads)
  5. • ϝοηʔδϯά • ಉظ/ඇಉظ • Interactive/PubSub • σʔλετΞ • εέʔϦϯά

    • σʔλΞΫηε • ࣮ߦํ๏ • ฒྻ/௚ྻ • ܾఆత/ඇܾఆత ໨తΛՌͨͨ͢Ίͷ࠷దղ͸ҟͳΔ
  6. • ಉظ • API Gateway • ඇಉظ • ௚ྻ •

    Kinesis Streams • ฒྻ • SNS • SQS • ͦͷଞ • Step Functions EVENTΛͲͷΑ͏ʹॲཧ͢΂͖͔ʁ
  7. • ґଘؔ܎ͷ޲͖Λἧ͑Δ • ඇಉظΛॏࢹ • Event SourceΛू໿఺ɾ෼ذ఺ͱ͢Δ • ෳࡶԽͷݪҼ͸େ఍σʔλΞΫηεʹ͋Δ •

    ॻ͖ࠐΈͱࢀরؔ܎ͷෳࡶԽ • σʔλͷॴ༗ؔ܎ • CQRS, Materialized View ෳࡶԽͤ͞ͳ͍ͨΊʹ
  8. • Cold Start/Warn StartΛҙࣝ͢Δ • ίʔυ͕ಉ͡Ͱ͋Ε͹Ұ౓ىಈͨ͠ίϯςφ͸͋Δఔ౓࢒Δʢ਺ेඵ) • ಉ͡ίϯςφ͕࠶ར༻͞ΕΔ -> Warm

    Start • ৽͍͠ίϯςφ্ཱ͕͕ͪΔ -> Cold Start (Φʔόʔϔου͕͋Δ) • ෆཁͳΦϒδΣΫτΛ޿͍ScopeͰੜ੒͠ͳ͍ • Warm Start࣌ʹ͸Global Scope΍StaticͳΦϒδΣΫτ͸࢒Δ • ࢖͍ճͤΔΦϒδΣΫτ͸࢖͍ճ͢(Lazy Loading, Singleton) • ಛʹTCPίωΫγϣϯ࣋ͬͯΔΦϒδΣΫτͱ͔͸Φʔόϔου͕σΧΠ͔Βେࣄ FaaSͷੑ্࣭ύϑΥʔϚϯεʹؔΘΔTips
  9. • Event Sourceͷछผຖʹॲཧํ๏ΛܾΊͯ౷Ұ͢Δ • ϝοηʔδͷड͚౉͠ํ • JSON/ProtocolBuffers, Plain/GZip etc… •

    Trace ID(ޙड़)ͳͲͷMetadataͷ࢓ࠐΈํ • ྫ֎ॲཧ • ແࢹʢϩάʹ࢒͢ʣͯ͠ྑ͍΋ͷ • ൃੜͨ࣌͠఺Ͱผϧʔτʹྲྀ͢΂͖΋ͷ • Failͤͯ͞ϦτϥΠػߏʹ৐ͤΔ΋ͷ • PythonͩͱDecoratorΛ࢖͏ͱศར EventॲཧͷϙΠϯτ
  10. • جຊతʹ࣮ࡍͷAWS αʔϏεΛ࢖ͬͯ΍Δ • ౷߹؅ཧͰ͖ΔFWΛબͿ(AWS SAM, Serverless etc…) • ͦͷ··ಉ͡؀ڥ͕σϓϩΠͰ͖Δ

    • ςετ͍ͨ͠ൣғΛܾΊɺऴ୺ͷEvent SourceͱHandlerΛஔ͖׵͑Δ • ؀ڥม਺ͰEvent SourceΛ੾Γସ͑ • VerifyՄೳͳܗͰOutputͤ͞Δ Integration Test
  11. • ࢖͏αʔϏε͕౷߹؅ཧͰ͖ΔFWΛબͿ(AWS SAM, Serverless etc…) • ઌड़ͷIntegration Testͷ࢓૊Έ͸CFnͷػೳʹڧ͘ґଘ͢ΔͷͰ
 CFnϕʔεͷFW͡Όͳ͍ͱ࢖͑ͳ͍ςΫχοΫ •

    ൣғ͕ݶఆతͳ΋ͷ͸ͦͷൣғͰऩ·Δ৔߹ʹͷΈ(Chalice, Apex etc…) • ͦͷൣғͰऩ·ΔͳΒศརͳͷͰੵۃతʹ࢖ͬͯྑ͍ Framework͸Կ࢖͏ʁ
  12. • ࣮ࡍʹ໰୊͕ى͖ͨ͜ͱΛ؂ࢹ͢Δ • Τϥʔͷൃੜ΍஗ԆΛ؂ࢹ͢Δ • API Gateway: Latency, 5XX Response

    • Lambda: Duration, Errors, Throttling, DeadLetterErrors • DynamoDB: Consumed Capacity, Throttling, Latency, Errors
 •Ұ൪େ੾ͳͷ͸ΞϓϦέʔγϣϯͷϩά ؂ࢹ
  13. • DeadLetterErrors • ͿͬͪΌ͚LambdaͷىಈError͸ى͖Δ࣌͸ͪΐ͍ͪΐ͍ى͖Δ • ࠶࣮ߦͰ্ख͘ݴͬͯΔέʔε͕΄ͱΜͲ • ࠶࣮ߦ΋ࣦഊͯ͠औΓ͜΅ͨ͠Error͸͜ΕΛݟͳ͍ͱ෼͔Βͳ͍(ཁઃఆ) • Throttling

    • SDK͸Throttlingͯ͠΋಺෦Ͱউखʹ࠶࣮ߦ͢Δ • Τϥʔ͕ى͖ͯͳ͍͔ΒThrottling͕ى͖ͯͳ͍ͱ͸ݶΒͳ͍ • ͜ΕΛݟΔͱൃੜঢ়گ͕෼͔ΔˠCapacity௥Ճ ཁ஫ҙͳ؂ࢹ߲໨
  14. • REST API + SPA/MobileAppͳΞϓϦέʔγϣϯ • ผʹѱ͘͸ͳ͍ • αʔόӡ༻͠ͳͯ͘ྑ͍Ҏ্ͷϝϦοτ͕ͳ͍ •

    ͦΕɺCaaS or PaaSͰΑ͘Ͷʁʁ • ී௨ʹRDB࢖͑ΔΑʁʁ • όοΫΤϯυॲཧΛ্ख͘෼ղͰ͖ͳ͍ͳΒແཧʹServerlessԽ͢Δඞཁ͸ͳ͍ • ࣮ࡍɺطଘWebΞϓϦͷServerlessԽ͸࡞Γ௚͢ؾ͕֓ͳ͚Ε͹
 ͍͍ͩͨίϯςφԽ, PaaSԽʹ଩੾Γ͢Δ͜ͱ͕΄ͱΜͲ WebΞϓϦέʔγϣϯʹผʹ޲͍ͯͳ͍