Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
無駄課金回避__lambdaでEC2定期シャットダウン.pdf
Search
naoki-urabe
January 11, 2023
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
無駄課金回避__lambdaでEC2定期シャットダウン.pdf
naoki-urabe
January 11, 2023
More Decks by naoki-urabe
See All by naoki-urabe
DevOps勉強会資料
naokiurabe
0
160
django入門
naokiurabe
0
120
django入門2
naokiurabe
0
88
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
370
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Being A Developer After 40
akosma
92
590k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Mobile First: as difficult as doing things right
swwweet
225
10k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
560
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Transcript
無駄課金回避!lambdaでEC2インスタンス定期シャットダウン naoki-urabe
自己紹介 DevOpsエンジニアやってます • デプロイ支援サービスの開発 • CI/CD導入 • Dockerfile作成etc 人生初LT!
時折見かける無駄に課金してしまったツイート • 全く身に覚えがないEC2インスタンスが起動しっぱなしになっているのを見つけた顔を している • AWSから請求きてて身に覚えがないけどEC2が無駄に起動しっぱなしだったから な… 無料枠の範囲から外れたのかな… • あぶねー。EC2が起動しっぱなしだった...無料枠内だからよかった。
自分もやらかし経験あり 円安の今は特につらい...
AWSの設定で予算アラートは設定できる ある額以上の利用をすると、メール通知される仕組み が、メール見てないと意味なし。。 普段メールがたくさん届いていると見落としがち
定期シャットダウンしてほしい 定期的にシャットダウンすることで無駄に課金してしまうことを回避できる やりたいこと • 毎日決まった時間にEC2が起動しているかをチェックし、停止して問題ないものを 停止する • AutoStopタグが付いているものを自動停止とする
lambda + cloudwatchで定期シャットダウンできる! CloudWatchで毎日決まった時間にlambda関数を実行できる lambda関数で止めて問題ないインスタンスを停止する
アーキテクチャ
停止処理の実装 pythonで実装 boto3ライブラリを使うことでawsリソースを操作できる
CloudWatchにevent rule追加 cron jobとして毎日22時に作成したlambda関数を実行するように設定する
仕組み導入後 仕組み導入の2022/10以降利用請求が抑えられた
まとめ、今後の展望 CloudWatchとlambdaでEC2停止忘れによる無駄な出費を抑えられた! Terraformでリソース管理していきたい