Skip to content

Instantly share code, notes, and snippets.

@netroy
Last active March 20, 2024 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save netroy/2f984060a7f5f8a8555f6b74f8bc14e9 to your computer and use it in GitHub Desktop.
Save netroy/2f984060a7f5f8a8555f6b74f8bc14e9 to your computer and use it in GitHub Desktop.
Use A Lambda function to send an SMS over Amazon Pinpoint
const appId = [[PINPOINT_APPLICATION_ID]];
const destination = [[YOUR_PHONE_NUMBER]];
const { Pinpoint } = require('aws-sdk');
const pinpoint = new Pinpoint();
const payloadFn = (appId, destination, message) => {
const ApplicationId = appId;
const Addresses = {};
Addresses[destination] = { ChannelType: 'SMS' };
const MessageConfiguration = {
SMSMessage: {
Body: message,
MessageType: 'TRANSACTIONAL',
SenderId: 'CloudwatchAlert'
}
};
return {
ApplicationId,
MessageRequest: {
Addresses,
MessageConfiguration
}
};
};
exports.handler = async event => {
const message = 'Testing';
const payload = payloadFn(appId, destination, message);
await pinpoint.sendMessages(payload).promise();
};
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:CreateLogGroup",
"logs:PutLogEvents",
"mobiletargeting:SendMessages"
],
"Resource": "*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment