首页 > 解决方案 > AWS SNS - how should I be sending message data, MessageAttributes?

问题描述

I'm building an application that enables clients to book appointments with service providers. I'm using SNS -> SQS -> Lambda to process various emails that need to be sent when booking an appointment. IE I currently send an SNS message like so (in node.js):

await sns.publish({
    Message: 'booking-request',
    TopicArn: process.env.AWS_BOOKING_REQUEST_TOPIC_ARN,
    MessageAttributes: {
      artistEmail: SNSMF.string(artist.email),
      artistName: SNSMF.string(artist.name),
      clientEmail: SNSMF.string(req.body.email),
      clientName: SNSMF.string(`${req.body.firstName} ${req.body.lastName}`),
      date: SNSMF.string(moment(req.body.date).tz(studio.timeZone).format())
    }
  }).promise();

This all works fine, but I'm using MessageAttributes to pass the pertinent appointment details so my notifications layer can send the proper emails.

My main questions is, am I using MessageAttributes in the proper way, or is there a better way to pass all of this data? Should the data be the message itself? I ask because I believe that you can only have 10 MessageAttributes and I'm going to run into a limit with the appointment details (currently collecting about 10-12 data points about the appointment that I want to include in the emails). Any ideas? Thank you!

标签: amazon-web-servicesamazon-sns

解决方案


通常,您希望传递的“主要”信息将在Body消息中。使用 JSON 传递各种类型的信息是很常见的。

MessageAttributes通常是关于消息本身而不是消息的内容,例如时间戳、优先级和用户信息。

鉴于您的要求,我将您的数据放入Body(例如 JSON 中)将避免达到限制并且也将更具可扩展性。


推荐阅读