Send an SMS via AWS SNS using boto3 in an AWS Lambda function?

前端 未结 1 1290
囚心锁ツ
囚心锁ツ 2021-02-02 15:13

I would like to send an SMS message from an AWS Lambda function using the boto3 publish method to notify the user of issues via SMS. My lambda function is written in Python and

1条回答
  •  抹茶落季
    2021-02-02 15:50

    Actually your example looks right. Here is what I tried

    import boto3
    sns = boto3.client('sns')
    number = '+17702233322'
    sns.publish(PhoneNumber = number, Message='example text message' )
    

    Worked like a charm. I recommend using awscli configured with your root account credentials first and take the code for a test drive. Once its working either create a new user with just the rights you need, or apply it to an Instance role.

    You need to create a policy that allows SNS:Publish on resource:* (allow texting to everyone) or resource: '+17702233322' (allow text to a specific number).

    0 讨论(0)
提交回复
热议问题