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
Amazon SNS からのメールをFirehoseとLambdaでまとめる / Deal m...
Search
shimo
April 10, 2022
900
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Amazon SNS からのメールをFirehoseとLambdaでまとめる / Deal many Amazon SNS mails with Firehose and Lambda
shimo
April 10, 2022
More Decks by shimo
See All by shimo
シェルスクリプトでAWSをいい感じに使いたい
shimo_s3
0
40
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
360
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Crafting Experiences
bethany
1
340
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Transcript
Amazon SNS からのメールを FirehoseとLambdaでまとめる 2022/4/11 JAWS-UG朝会 #32 LT @shimo_s3 1
もくじ 自己紹介 動機 やってみた① やってみた② まとめ 2
自己紹介 名前 : shimo : @shimo_s3 職業 : フリーランスのITエンジニア AWS:
認定12冠、Community Builder 好き : 自動化、データ分析、サーバレス 3
動機 「人の困り」 「自分が知らなかったので使ってみたい」 4 Amazon SNSでエラー通知受けてるけど、大量に来すぎ。まとめたい。。。 イベント@2022/1/26 2021 Amazon SNS
主要Update 「Amazon SNS が、Kinesis Data Firehose サブスクリプションを介してメッセージの アーカイブと分析のサポートを追加 (2021/01/12)」 @Twitter
やってみた① SNS→Firehose→S3 trigger→Lambda SNSを集約できる。ただし、間隔は最大15分(Firehoseの制限) ・大量のSNSをFirehoseで溜めて、 S3に置く(設定は簡単) ・置いた時点で、S3 triggerで Lambdaを呼ぶ ・Lambdaは、S3に置かれたオブジェクトを取り
出して、中のSNSのデータを整理する(Python) ・Lambdaがまとめたデータを別のSNSで送る 5
やってみた② EventBridgeでLambdaをCRONトリガする ①を拡張。時間単位で自由にスケジュールできる 1. EventBridgeがLambdaをトリガする 2. LambdaがEventBridgeのCRON設定を取得し、 直前の実行時間を逆算、どれが未処理かを把握 3. Lambdaが未処理のフォルダ内のデータを取得し、
まとめる※defaultフォルダ構成 yyyy/mm/dd/hh を活用 2 1 例: cron(0, 9-17/2, *, *, *, *) 【9-17時で2時間おき】の場合 now=13:00なら直前は11:00, now=9:00なら直前は17:00 3 6
SNSのデータをLambdaでまとめる jsonデータからPythonで抽出 7 data = { "Type": "Notification", "MessageId": "xxxx-xxxx",
"TopicArn": "arn:aws:sns:region:account-id:Topic", "Subject": "sub1", "Message": "This is the message 1!", "Timestamp": "2022-02-03T08:31:11.031Z", "UnsubscribeURL": "(略)" } json_obj = json.loads(data) json_obj["Timestamp"] json_obj["Message"] S3に保存されるデータの例 (SNS Publish 1回分) 任意の項目を抽出
集約して別SNSで送信した例 自由に文を入れている 2回分のTimestamp,Messageを抽出 unsubscribe文は1回 (別SNSの分) 8
まとめ 大量のSNSメールをまとめて取得することができた • FirehoseでバッファしてS3に置いて、Lambdaをトリガして整形し、別SNSでユーザに送信 • 時間単位で自由にCRON設定して、EventBridgeでLambdaを呼び出す ◦ 呼ばれたLambdaがEventBridegeからCRON scheduleを取得して、直前の呼び出し時 間、未処理分を逆算
◦ Firehose→S3のデフォルト フォルダ構成をそのまま活用 (※本スライドの内容は、コードも含めて Mediumに投稿済みです) • How to deal many Amazon SNS messages with Firehose and Lambda • Hourly Query Firehose S3 bucket with EventBridge and Lambda 9