Use Lambda to send alert to SNS Topic – but only send email once per unique body

I have an IoT workflow with various devices sending data to an S3 bucket, which triggers a Lambda. The Lambda processes the data and may trigger an alert (e.g. due to DeviceX having a temperature above Y). I wish to receive email alerts when a new device encounters such an alert with a maximum of receiving one email per device per day.

The solution I am hoping to implement is to setup the SNS writer to output an email body for the SNS Topic endpoint which includes the device ID (which is globally unique across my devices), the alert ID and the date.

In the SNS setup I want to make it so that my subscribers receive an email when the first such event happens. But since the Lambda may be triggered several times per hour by the same device ID, they should not receive a new email for every such invocation, even if the alert condition is still true. If another device encounters an alert, that should still trigger a new separate email – and similarly, if the first device continues to be in the alert state the next day, a new email will be sent because now the date changes.

I believe this may be linked to subscription filters or deduplication, but I have not been able to find the right solution for this.

The SNS message filtering feature is not helpful for this use case. The SNS deduplication feature only works within a 5 minute time window. You can’t count on SNS to handle this for you if you care about a 24 hour time period. You need to have code in your Lambda function that determines if it actually needs to send the message to SNS or if the same message has already been sent recently.

The best way to handle this is to create a DynamoDB table that your Lambda function stores your message in before it sends them. Before sending a message, it would check if that message already exists in the DynamoDB table, if so, it would skip sending the message to SNS.

You would configure TTL expiration on the DynamoDB messages, so that they are automatically deleted from the table after 24 hours.


One thing to be aware of, the record in DynamoDB may not actually be deleted until some time after the TTL value expires. So for the solution to be more precise, your Lambda function would need to check if the message already exists in the database, and if it does exist, compare the record’s TTL value against the current time before deciding if it should skip sending the message again.

Recognized by AWS

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật