Skip to content

Message attribute names starting with 'AWS.' or 'Amazon.' are reserved for use by Amazon. - Nodejs

0

I'm integrating AWS SNS to send messages to Indian mobile numbers, having already registered my SenderID with DLT and obtained approval from AWS. However, when attempting to include the EntityID and TemplateID in my code as instructed by AWS, I'm encountering an error stating 'Message attribute names starting with 'AWS.' or 'Amazon.' are reserved for use by Amazon.' Where exactly should I include these IDs in my AWS SNS code to resolve this issue?

const sendSnsMessage = async (message, phone) => {
  try {
    let params = {
      Message: message,
      PhoneNumber: phone,
      MessageAttributes: {
        "AWS.SNS.SMS.SMSType": {
          DataType: "String",
          StringValue: "Transactional",
        },
        "AWS.SNS.SMS.SenderID": {
          DataType: "String",
          StringValue: <my-sender-id>,
        },
        "AWS.SNS.SMS.EntityID": {
          DataType: "String",
          StringValue: <entity-id>,
        },
        "AWS.SNS.SMS.TemplateID": {
          DataType: "String",
          StringValue: <template-id>,
        },
      },
    };

    let publishCmd = new PublishCommand(params);
    let sentMsg = await SNS.send(publishCmd);
    return sentMsg;
  } catch (error) {
    console.log("errrr",error.message);
  }
};

edit : Removed AWS prefix from EntityID and TemplateID, resolving reserved attribute error, but now receiving SMS with short number; how to use registered SenderID with AWS SNS for Indian mobile numbers?

AWS SenderID accepted mail AWS SenderID accepet mail

2 Answers
1

The MessageAttributes object is used to specify additional metadata for the SMS message, including the AWS.MM.SMS.EntityId and AWS.MM.SMS.TemplateId parameters.

In the provided code snippet:

"AWS.SNS.SMS.EntityID": {
   DataType: "String",
   StringValue: <entity-id>,
},
"AWS.SNS.SMS.TemplateID": {
   DataType: "String",
   StringValue: <template-id>,
}

The parameter name AWS.SNS.SMS.EntityID and AWS.SNS.SMS.TemplateID are not correct. According to the AWS documentation, the correct parameter name are AWS.MM.SMS.EntityId and AWS.MM.SMS.TemplateId.

The code should be updated as follows:

"AWS.MM.SMS.EntityId": {
   DataType: "String",
   StringValue: <entity-id>,
},
"AWS.MM.SMS.TemplateId": {
   DataType: "String",
   StringValue: <template-id>,
}

Please make the necessary corrections to ensure that the correct parameter names are used when specifying the entity ID and template ID for SMS messages.

AWS
EXPERT

answered 2 years ago

  • After resolving the reserved attribute error by modifying the code, I'm now encountering an issue where SMS messages are being sent from random numbers instead of my registered SenderID; how can I configure AWS SNS to use my registered SenderID for Indian mobile numbers?

  • Share your modified complete code for review

  • An issue where messages are sent from random number instead of SenderID has resolved by adding the SNS policy on AWS End User Messaging console; thanks:)

-1

The error you're encountering is due to the incorrect use of reserved message attribute names in your AWS SNS code. AWS reserves attribute names starting with 'AWS.' or 'Amazon.' for their own use, and you cannot directly set these attributes in your code.

For sending SMS messages to Indian mobile numbers with DLT (Distributed Ledger Technology) compliance, you need to include the EntityID and TemplateID, but not as reserved AWS attributes. Instead, you should include these as custom message attributes.

Here's how you can modify your code to correctly include the EntityID and TemplateID:

const sendSnsMessage = async (message, phone) => {
try {
let params = {
Message: message,
PhoneNumber: phone,
MessageAttributes: {
"AWS.SNS.SMS.SMSType": {
DataType: "String",
StringValue: "Transactional",
},
"AWS.SNS.SMS.SenderID": {
DataType: "String",
StringValue: "YOUR_SENDER_ID",
},
"EntityId": {
DataType: "String",
StringValue: "YOUR_ENTITY_ID",
},
"TemplateId": {
DataType: "String",
StringValue: "YOUR_TEMPLATE_ID",
},
},
};

let publishCmd = new PublishCommand(params);
let sentMsg = await SNS.send(publishCmd);
return sentMsg;
} catch (error) {
console.log("error", error.message);
}
};

In this modified version:

  1. We've kept the reserved attributes "AWS.SNS.SMS.SMSType" and "AWS.SNS.SMS.SenderID" as they are.
  2. We've added "EntityId" and "TemplateId" as custom message attributes, without the "AWS.SNS.SMS." prefix.

By making these changes, you should be able to include your EntityID and TemplateID without encountering the error about reserved attribute names. Remember to replace "YOUR_SENDER_ID", "YOUR_ENTITY_ID", and "YOUR_TEMPLATE_ID" with your actual values.

This approach allows you to comply with DLT requirements for sending SMS to Indian mobile numbers while adhering to AWS SNS's rules about reserved attribute names.
Sources
Publishing with platform-specific payloads - Amazon Simple Notification Service
Amazon SNS now supports sending SMS from five new regions

answered 2 years ago

  • Removed AWS prefix from EntityID and TemplateID, resolving reserved attribute error, but now receiving SMS with random number; how to use registered SenderID with AWS SNS for Indian mobile numbers?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.