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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
46
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Ethics towards AI in product and experience design
skipperchong
2
420
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
610
It's Worth the Effort
3n
188
29k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Navigating Team Friction
lara
192
16k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
350
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Mind Mapping
helmedeiros
1
390
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