In this tutorial, I will show you how to use AWS Simple notification service (SNS) for sending AMS in PHP.
What is the Simple Notification Service?
Amazon Simple Notification Service (SNS) is a highly available, durable, secure, fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications. Amazon SNS provides topics for high-throughput, push-based, many-to-many messaging.
1 . Create IAM User
First step will be, You have to create IAM User in AWS Account for sending SMS via AWS SDK. You can follow below images to create IAM user. Go to this link – Click here
Click on Users link
Click on Add User button. Provide the IAM username and select Programmatic access in Access type. Click on Next:permission button.
Select Attach existing policies directly tab and under that search with sns keyword. In result, Select these 3 policies :-
Click on Next:tags . You can provide tags or you can leave tags portion.
Review User details and Permission summary before creating the user. After reviewing Click on Create User. Save your Access Key Id and Secret Access Key.
IAM user created successfully.
2 . Install AWS SDK in your project
AWS provides an SDK for developers to sending a SMS. For installation you have to type below command in the terminal.
3 . Create a Send SMS Service
Copy the below code and paste it in your SMS Service. Don’t forget to change the IAM User credentials Key and Secret that you generated. Change the AWS SNS region if you use another region for sending SMS.
You have validated SenderId than you can provide the SenderId if you don’t than you have to validate by customer support of AWS or you can comment it out that portion.
Change SMS type, it will me transactional or promotional. You can change according to your need.
Provide the message which you want to send to the user.
In phone number you have to attach phone number with country code.
I hope, now you can integrate the SMS Service into your project easily. If you can’t understand something in this blog or you got an error in code, You can watch my video tutorial which will help you.
I would like to hear your thoughts or suggestions in the comment section.