如何通过AWS Lambda函数使用Amazon SNS发送SMS [英] How to send SMS using Amazon SNS from a AWS lambda function
问题描述
Amazon SNS提供了一种在全球范围内发送SMS的功能.
Amazon SNS provides a facility to send SMS globally.
我想通过Lambda函数发送短信,因为我们提供了手机号码和短信,并使用SNS传递了该短信,但是我没有找到有用的NodeJS或Java文档或示例代码.
I want to send SMS from a Lambda function were we provide the mobile number and text message and use SNS to deliver that message but I didn't find a helpful documentation or example code for NodeJS or java.
任何人都可以提出解决方案吗?
Can any one suggest a solution?
代码:
var params = {
Message: 'Hi this is message from AWS_SNS', /* required */
MessageAttributes: {
someKey: {
DataType: 'String' ,
StringValue: 'String'
},
},
MessageStructure: 'String',
PhoneNumber: '+91MyNUMBER',
Subject: 'MYSubject',
//TargetArn: 'arn:aws:sns:us-west-2:798298080689:SMS',
//TopicArn: 'arn:aws:sqs:us-west-2:798298080689:SendSMS'
};
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
推荐答案
因此,您需要编写通过某种方式调用的Lambda函数,例如通过HTTP请求,因此您还需要设置API网关以将连接路由到您的Lambda函数.
So, you need to write Lambda function which is invoked somehow, let's say via HTTP request so you'll also need to setup API Gateway to route connections to your Lambda function.
接下来,您的Lambda函数会将数据推送到"SNS主题",而SMS订阅将轮询"该主题"中的任何新数据.只要有任何数据进入该主题,订阅便会使用这些数据,并且将发送SMS.
Next, your Lambda function will push that data to "SNS Topic" while SMS Subscription will "poll" for any new data in this "Topic". As soon as any data gets into this topic, it will be consumed by subscription and SMS will be sent.
几天前,我写了一篇有关SNS&Lambda可能会对您有所帮助.您想要实现的流程与本文描述的流程非常相似.
Few days ago I wrote a post about SNS & Lambda which might help you. Flow you wanted to achieve is pretty similar to one described in this article.
Documentation pages that might help:
- 推送到SNS: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property
- 订阅SNS: http://docs.aws.amazon.com/sns/latest/dg/SubscribeTopic.html
这篇关于如何通过AWS Lambda函数使用Amazon SNS发送SMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!