I recently developed a project that needs to send a text message, Amazon's sns, with the old version I could send it smoothly, but with the new one I'm not able to send it to a PhoneNumber (I can still send it with v2, but it will be discontinued and I cannot run the risk of the application stopping), how can I send it? I tried it this way:
const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");
const { fromEnv } = require("@aws-sdk/credential-providers");
async function sendMessage(message, phoneNumber) {
const snsClient = new SNSClient({
credentials: fromEnv(),
region: process.env.AWS_REGION,
});
const params = {
Message: message,
PhoneNumber: phoneNumber, // Use this to send directly to a phone number
};
try {
const command = new PublishCommand(params);
const data = await snsClient.send(command);
console.log("SMS SEND SUCCESS", data);
} catch (err) {
console.log("Error", err);
}
}
module.exports = { sendMessage };
But dont work, just return:
Error: {
Type: 'Sender',
Code: 'InvalidParameter',
Message: 'Invalid parameter: TopicArn or TargetArn Reason: no value for required parameter',
message: 'Invalid parameter: TopicArn or TargetArn Reason: no value for required parameter'
}
The above issue can occur in any of the following scenario:
For this case re-installing the SDK worked.