AnySMS::Backend::AWS
AnySMS backend to send sms using AWS SNS service.
Before installation - obtaining token
Before you can use this gem, you should get tokens from amazon web services (AWS). Here are steps to achieve that:
-
Go to AWS registration page
-
After you registered and logged in, go to IAM users
-
Click "Create new users", enter username of your wish (in my case
testuser
) and then click "Create". -
You should see similar picture:
save access key id and secret acces key somwhere.
-
Now close popup and click on the user.
-
Click Permissions tab. It will look like this
-
Click on Attach Policy, then filter by SNS.
-
Check AmazonSNSFullAccess, click Attach Policy (at the bottom)
This is simple example on how to get them and make things work quick. In reality AWS support various access options, you may read them here and configure it more strict or closer to your needs.
Installation & usage
Add this line to your application's Gemfile:
gem "any_sms-backend-aws", "~> 1.0"
Then somewhere in your initialization code:
require "any_sms-backend-aws"
AnySMS.configure do |c|
c.register_backend(:my_aws_backend,
AnySMS::Backend::AWS,
access_key: ENV["AWS_ACCESS_KEY"],
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"],
region: ENV["AWS_REGION"], # Optional, default will be "us-east-1"
default_sender_id: ENV["AWS_SNS_DEFAULT_SENDER_ID"] # Optional
)
c.default_backend = :my_aws_backend
end
This is an simple example configuration.
Before running application you should specify
AWS_ACCESS_KEY
, AWS_SECRET_ACCESS_KEY
environment variables.
Optionally you can specify AWS_REGION
and AWS_SNS_DEFAULT_SENDER_ID
(sms sender as text instead of phone).
Keep in mind that AWS_SNS_DEFAULT_SENDER_ID
is changing ACCOUNT SETTINGS,
and is NOT per request. In case you know how to set it per request - please open issue.
!!Make sure you never commit credentials (secrets) to your repository!!
Now, whenever you need to send SMS, just do:
# Will immediately send sms using AWS sns
AnySMS.send_sms("+10000000000", "My sms text")
For more advanced usage please go to AnySMS documentation
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/Fedcomp/any_sms-backend-aws.
License
The gem is available as open source under the terms of the MIT License.