Skip to content

Instantly share code, notes, and snippets.

@SalvoCozzubo
Created April 18, 2022 19:46
Show Gist options
  • Save SalvoCozzubo/4a9e16d8f4f468d63b72108d4d3b1737 to your computer and use it in GitHub Desktop.
Save SalvoCozzubo/4a9e16d8f4f468d63b72108d4d3b1737 to your computer and use it in GitHub Desktop.
Send SMS with AWS SNS
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns';
const client = new SNSClient({});
const handler = async (event) => {
if (!event.body) {
return { message: 'Body not found' }
}
const { numberPhone, text } = JSON.parse(event.body);
const params = {
PhoneNumber: numberPhone,
Message: text,
};
try {
await client.send(new PublishCommand(params));
return { message: 'Sms send successfully' };
} catch (error) {
return { message: error.message }
}
};
export { handler };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment