Skip to content

Instantly share code, notes, and snippets.

@netroy
Last active March 20, 2024 18:49
Show Gist options
  • Select an option

  • Save netroy/2f984060a7f5f8a8555f6b74f8bc14e9 to your computer and use it in GitHub Desktop.

Select an option

Save netroy/2f984060a7f5f8a8555f6b74f8bc14e9 to your computer and use it in GitHub Desktop.

Revisions

  1. netroy revised this gist Nov 19, 2019. No changes.
  2. netroy created this gist Nov 19, 2019.
    35 changes: 35 additions & 0 deletions lambda-pinpoint.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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();
    };
    15 changes: 15 additions & 0 deletions lambda-policy.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Action": [
    "logs:CreateLogStream",
    "logs:CreateLogGroup",
    "logs:PutLogEvents",
    "mobiletargeting:SendMessages"
    ],
    "Resource": "*"
    }
    ]
    }