Last active
March 20, 2024 18:49
-
-
Save netroy/2f984060a7f5f8a8555f6b74f8bc14e9 to your computer and use it in GitHub Desktop.
Use A Lambda function to send an SMS over Amazon Pinpoint
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
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(); | |
}; |
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
{ | |
"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