This error shows that :
The instance does not include the AWS command, so we need to install it.
We also need to give the instance permission to call the SNS publish API. The best way to do this is with a role:
1. Create the role in the IAM console , the role needs permission to invoke the sns:Publish action. I’ve included a minimal policy document below.
- a. Go to the IAM console.
- b. Click on roles on the right.
- c. Click on create role.
- d. Select EC2 under common use cases.
- e. Click Next: Permissions at the bottom.
- f. Click Create Policy.
- g. Go to the JSON tab.
- h. Paste in the policy from below, overwriting what is already there.
- i. Click on Review Policy at the bottom.
- j. Give it a name, then click on Create policy at the bottom.
- k. Close the tab and return to where you were creating the role.
- l. Click on the refresh button at the top right of the table of policies.
- m. Find the policy you just created and tick the box next to it.
- n. Click on Next: Tags at the bottom, then Next: Review.
- o. Give the role a name.
- p. Click on Create role at the bottom.
2. Attach the newly created role to your EC2 instance .
- a. Go to the list of your EC2 instances.
- b. Select your instance.
- c. Go to Actions > Instance Settings > Attach/Replace IAM Role.
- d. In IAM Role, select the role you just created.
- e. Click on Apply.
Now that we have a role, and attached it to the instance, connect to the instance and run the commands below to install the AWS CLI and to send an SMS.
$ sudo su
$ yum install unzip -y
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip " -o "awscliv2.zip"
$ unzip awscliv2.zip
$ usr/local/bin/aws sns publish --phone-number +918011501382 --message 'hello'
An SMS should have been sent to the number in the above command. If this is not the case, will you please reply to me with the error.
After this has been accomplished successfully, we’ll get PHP and the AWS PHP SDK setup together. Do you have any special requirements for this step?
--- JSON Policy ---