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

シェルスクリプトをサーバーレスで cron したい

Yasuhiroki
February 02, 2022

シェルスクリプトをサーバーレスで cron したい

自動化大好きエンジニアLT会 - vol.6 の発表資料です。
Serverless Framework を用いて、 awscli が動く Lamdba を構築してシェルスクリプトをサーバーレスに実行するという内容です。

Yasuhiroki

February 02, 2022
Tweet

More Decks by Yasuhiroki

Other Decks in Technology

Transcript

  1. γΣϧεΫϦϓτΛ
    αʔόʔϨεͰ
    DSPO͍ͨ͠
    !ZBTVIJSPLJ
    ࣗಈԽେ޷͖ΤϯδχΞ-5ձWPM

    View full-size slide

  2. !ZBTVIJSPLJͷझຯ
    w ࢠͲ΋ͷ$IBOHF-PHΛॻ͘

    View full-size slide

  3. !ZBTVIJSPLJͷ࢓ࣄ
    w ΈΜνϟϨ 3BJMT"84"OESPJE

    View full-size slide

  4. !ZBTVIJSPLJͷ࢓ࣄ
    w ΈΜνϟϨ 3BJMT"84"OESPJE

    View full-size slide

  5. γΣϧεΫϦϓτΛ
    αʔόʔϨεͰ
    DSPO͍ͨ͠ཉ

    View full-size slide

  6. ͳͥγΣϧεΫϦϓτͳͷ͔

    View full-size slide

  7. γΣϧ͕ੜ׆؀ڥ͔ͩΒ
    w HJUͷDPNNJUΛ੔ཧ͍ͨ͠

    ɹˠHJUSFCBTFJ
    w αʔόʔͷϩά͕ݟ͍ͨ

    ɹˠBXTMPHT

    View full-size slide

  8. ૊Έ߹Θͤࣗ༝ࣗࡏ
    w ؀ڥม਺Λ+40/ʹ͍ͨ͠

    ɹˠFOWcTFETa <>a
    aaacKPQ

    View full-size slide

  9. ແݶͷՄೳੑ͕͋Δ
    w AAACBTI

    Q


    FDIPFDIPແݶͷՄೳੑ

    AAA

    View full-size slide

  10. ͳͥαʔόʔϨεͳͷ͔

    View full-size slide

  11. ਎ܰͰ͋Γ͍ͨ
    w αʔόʔΛ࣋ͪͨ͘ͳ͍ ෺ཧతͳҙຯͰ

    w ͓ۚΛ͔͚ͨ͘ͳ͍

    View full-size slide

  12. ͳͥDSPOͳͷ͔

    View full-size slide

  13. ࣗಈͰ࣮ߦ͍ͨ͠
    w ࣗಈԽͨ͠ॲཧͷ࣮ߦ΋ࣗಈԽ͍ͨ͠
    w ࣮ߦ͢Δ͜ͱΛ҆৺ͯ͠๨Ε͍ͨ

    View full-size slide

  14. ఆظ࣮ߦ͍ͨ͠
    w ೔ճ͍ͭͰ΋ྑ͍͔Β࣮ߦ͍ͨ͠

    View full-size slide

  15. ͲͷΑ͏ʹ࣮ݱ͢Δ͔

    View full-size slide

  16. "84-BNCEB


    "NB[PO$MPVE8BUDI
    &WFOUT

    View full-size slide

  17. "84-BNCEB
    w "84ͷαʔόʔϨεͳαʔϏε
    w γΣϧεΫϦϓτ΋σϓϩΠͰ͖Δ ޙड़

    View full-size slide

  18. "NB[PO$MPVE8BUDI&WFOUT
    w DSPOͷΑ͏ʹ࣌ؒࢦఆΛͯ͠ɺ

    ಛఆͷ"84-BNCEBΛ࣮ߦͰ͖Δ

    View full-size slide

  19. 4FSWFSMFTT'SBNFXPSL

    View full-size slide

  20. 4FSWFSMFTT'SBNFXPSL
    w ೥͔Β͋Δ/PEFKT੡πʔϧ
    w ʹW͕ެ։
    https://www.serverless.com

    View full-size slide

  21. 4FSWFSMFTT'SBNFXPSL
    w 4FSWFSMFTTΛӡ༻͍ͯ͠Δاۀͷ͸ɺ

    4FSWFSMFTT'SBNFXPSLΛར༻͍ͯ͠Δ
    https://www.datadoghq.com/ja/state-of-serverless/

    View full-size slide

  22. 4FSWFSMFTT'SBNFXPSL
    w "84 ʹݶΒͳ͍
    ͷϦιʔεΛ

    :".-ϑΝΠϧͭͰҰׅ؅ཧͰ͖Δ
    w TFSWFSMFTTίϚϯυ TMTίϚϯυ
    Ͱ

    ࡞੒ߋ৽࡟আͳͲ͕Ͱ͖Δ

    View full-size slide

  23. ࣮ྫ༻γΣϧεΫϦϓτ
    w ࠓ೔͕ૉ਺ͳ೔ͳͷ͔ૉఢͳ೔ͳͷ͔ڭ͑ͯ͘ΕΔ
    w ݁Ռ͸4ʹΞοϓϩʔυ͞ΕΔ
    w AAACBTI

    VTSCJOFOWCBTI

    EBUF:NEUNQSFTVMUUYU

    EBUF:NEcGBDUPScBXL/'\QSJOUࠓ೔΋ૉ਺Ͱ
    ͢Ͷ^/'\QSJOUࠓ೔΋ૉఢͰ͢Ͷ^UNQSFTVMUUYU

    BXTTDQUNQSFTVMUUYUTZBTVIJSPLJSFTVMUUYU

    AAA

    View full-size slide

  24. ॳظηοτΞοϓ
    w TFSWFSMFTTΛΠϯετʔϧ
    w AOQNJOTUBMMHTFSWFSMFTTA
    w TFSWFSMFTTίϚϯυ͕࢖͑ΔΑ͏ʹͳΔ
    w ୹͍TMTίϚϯυ΋༻ҙ͞Ε͍ͯΔ

    View full-size slide

  25. ॳظηοτΞοϓ
    w "84ͷDSFEFOUJBMTͷઃఆ
    w IUUQTEPDTBXTBNB[PODPNKB@KQ
    DMJMBUFTUVTFSHVJEFDMJDPO
    fi
    HVSF
    fi
    MFTIUNM

    View full-size slide

  26. ϓϩδΣΫτΛ࡞੒͢Δ
    w BXTQSPWJEFEςϯϓϨʔτΛ࢖͏
    w ATMTDSFBUFUFNQMBUFBXTQSPWJEFEA
    w "84-BNCEBͷΧελϜϥϯλΠϜΛ࣮ߦ
    ͢ΔϑΝΠϧ͕༻ҙ͞Ε͍ͯΔ
    w ಛʹCPPUTUSBQͱ͍͏ϑΝΠϧ͕ॏཁ

    View full-size slide

  27. -BNCEBͷΧελϜϥϯλΠϜ
    w QVCMJDFDSBXTMBNCEBQSPWJEFEͱ͍͏Π
    ϝʔδͷίϯςφ͕ىಈ͢Δ
    w ίϯςφ಺ͰCPPUTUSBQ͕࣮ߦ͞ΕΔ
    w CPPUTUSBQͰ-BNCEBͷ"1*Λ࣮ߦ͠ɺ

    ىಈ࣌ͷύϥϝʔλͷऔಘ΍ɺ

    ׬ྃ࣌ͷϨεϙϯεΛฦ͞ͳ͚Ε͹ͳΒͳ
    ͍
    ิ଍

    View full-size slide

  28. γΣϧεΫϦϓτΛ࣮૷
    w BXTQSPWJEFEςϯϓϨʔτͰ͸

    IBOEMFSTIͷIFMMPؔ਺͕࣮ߦ͞ΕΔ
    w ࠓճ͸ผϑΝΠϧNBJOTIΛݺͼग़͢Α͏
    ʹ͢Δ
    handler.sh main.sh

    View full-size slide

  29. ಈ࡞֬ೝ
    w ϩʔΧϧ؀ڥͰಈ࡞֬ೝͰ͖Δ
    w ATMTJOWPLFMPDBMGIFMMPA
    w BXTίϚϯυ͕ͳ͍

    View full-size slide

  30. BXTDMJ͸ೖ͍ͬͯͳ͍
    w QVCMJDFDSBXTMBNCEBQSPWJEFEΠϝʔδ
    ʹ͸BXTDMJ͸ະΠϯετʔϧ
    w QZUIPO͸͋Δ
    w QJQJOTUBMM͢Ε͹࢖͑Δ ͱࢥ͏

    ิ଍

    View full-size slide

  31. BXTDMJΛ࢖͏ʹ͸ʁ
    w ຖճQJQJOTUBMM͢Δ
    w ΧελϜΠϝʔδΛར༻͢Δ
    w -BNCEBϨΠϠʔΛར༻͢Δ

    View full-size slide

  32. BXTDMJΛ࢖͏ʹ͸ʁ
    w ຖճQJQJOTUBMM͢Δͷ͸ແବ͕͞ਏ͍
    w ίϯςφΠϝʔδͷ࡞੒ͱ؅ཧ͸໘౗
    w 4FSWFSMFTT'SBNFXPSL͸

    -BNCEBϨΠϠʔΛαϙʔτ͍ͯ͠Δ
    w ࠓճ͸-BNECBϨΠϠʔΛར༻͢Δ

    View full-size slide

  33. -BNECBϨΠϠʔ
    w -BNCEBͷ࣮ߦ؀ڥʹϑΝΠϧΛ௥ՃͰ͖Δ
    w ϏδωεϩδοΫͱOPEF@NPEVMFTͱ͔
    ϝλσʔλͳͲΛ෼཭Ͱ͖Δ
    w [JQϑΝΠϧΛϨΠϠʔͱͯ͠Ξοϓϩʔυ
    w ϨΠϠʔ͸APQUAҎԼʹల։͞ΕΔ
    ิ଍

    View full-size slide

  34. BXTDMJͷϨΠϠʔΛ࡞Δ
    w ςϯϓϨʔτΛ༻ҙ͠·ͨ͠
    w IUUQTHJUIVCDPNZBTVIJSPLJTFSWFSMFTT
    BXTDMJUFNQMBUF
    w ϓϩδΣΫτ࡞੒࣌ʹࢦఆ͢Δ
    w ATMTDSFBUFUFNQMBUFVSMIUUQT
    HJUIVCDPNZBTVIJSPLJTFSWFSMFTTBXTDMJ
    UFNQMBUFA

    View full-size slide

  35. BXTDMJͷϨΠϠʔΛ࡞Δ
    w ςϯϓϨʔτʹؚ·ΕΔMBZFSTIΛ࣮ߦ͢Δ
    w MBZFSσΟϨΫτϦ͕࡞ΒΕΔ

    View full-size slide

  36. MBZFSTI͕͢Δ͜ͱ
    w BXTDMJ͕ೖͬͨMBZFSσΟϨΫτϦΛ࡞੒͢Δ
    w QVCMJDFDSBXTMBNCEBQSPWJEFEίϯςφΛىಈ
    w BXTDMJΛΠϯετʔϧ
    w BXTDMJͷ࣮ߦʹඞཁͳϑΝΠϧΛ

    ϗετଆͷMBZFSσΟϨΫτϦʹίϐʔ͢Δ
    w "84$%,΋ಉ͡Α͏ʹBXTDMJ͕ಈ͘-BNCEBϨΠϠʔΛ࡞͍ͬͯΔ
    w IUUQTEPDTBXTBNB[PODPNDELBQJWEPDT!BXT
    DEL@MBNCEBMBZFSBXTDMJ"XT$MJ-BZFSIUNM
    ิ଍

    View full-size slide

  37. BXTDMJͷϨΠϠʔΛ࡞Δ
    w TFSWFSMFTTZBNMʹMBZFSTΛهड़͢Δ
    w ςϯϓϨʔτ͔Βੜ੒ͨ͠৔߹͸هड़ࡁΈ

    View full-size slide

  38. BXTDMJͷϨΠϠʔΛ࡞Δ
    w TMTEFQMPZͰϨΠϠʔ͕࡞੒͞Εɺ

    -BNCEBͰBXTίϚϯυ͕࢖͑ΔΑ͏ʹͳ
    Δ
    w ࣮ࡍʹ͸APQUBXTDMJBXTAͱ͍͏ύεʹ
    ͳΔ
    w 1"5)͕௨ͬͯͳ͍ͷͰ௨͔͢ɺઈରύε
    ͰBXTίϚϯυΛར༻͢Δ

    View full-size slide

  39. ࣮ྫ༻γΣϧεΫϦϓτΛमਖ਼
    w ࠓ೔͕ૉ਺ͳ೔ͳͷ͔ૉఢͳ೔ͳͷ͔ڭ͑ͯ͘ΕΔ
    w ݁Ռ͸4ʹΞοϓϩʔυ͞ΕΔ
    w AAACBTI

    VTSCJOFOWCBTI

    EBUF:NEUNQSFTVMUUYU

    EBUF:NEcGBDUPScBXL/'\QSJOUࠓ೔΋ૉ਺Ͱ
    ͢Ͷ^/'\QSJOUࠓ೔΋ૉఢͰ͢Ͷ^UNQSFTVMUUYU

    PQUBXTDMJBXTTDQUNQSFTVMUUYUTZBTVIJSPLJ
    SFTVMUUYU

    AAA

    View full-size slide

  40. ಈ࡞֬ೝ
    w ϩʔΧϧ؀ڥͰಈ࡞֬ೝ͢Δ
    w ATMTJOWPLFMPDBMGIFMMPA
    w BXTίϚϯυ͕࢖͍͑ͯΔ

    View full-size slide

  41. "84$MPVE8BUDI&WFOUTΛઃఆ͢Δ
    w TFSWFSMFTTZNMͷFWFOUTΛهड़͢Δ
    w 65$ +45
    ʹఆظతʹ࣮ߦ͢Δ

    View full-size slide

  42. ׬੒σϓϩΠ
    w σϓϩΠ
    w ATMTEFQMPZA

    View full-size slide

  43. ݁Ռ
    w ே࣌ʹੜ੒͞Ε͍ͯΔ
    w ࠓ೔͸ૉఢͰͨ͠

    View full-size slide