Created
April 18, 2022 19:46
-
-
Save SalvoCozzubo/4a9e16d8f4f468d63b72108d4d3b1737 to your computer and use it in GitHub Desktop.
Send SMS with AWS SNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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