Skip to content
Snippets Groups Projects
Commit f0b18892 authored by nimrod's avatar nimrod
Browse files

Migrate to another SMS sending service.

It turns out that Twilio is quite expensive, more than I willing to pay
for this service. So I'm going with MessageBird.
parent 27183d50
No related branches found
No related tags found
No related merge requests found
Pipeline #2572 passed
variable "twilio_account_sid" {
description = "Twilio account SID."
}
variable "twilio_api_key" {
description = "Twilio API key."
}
variable "twilio_api_secret" {
description = "Twilio API secret."
variable "messagebird_access_key" {
description = "MessageBird API access key."
}
# It would have been nicer to buy the phone number with Terraform and the
......@@ -39,11 +31,8 @@ resource "aws_lambda_function" "sms_notify" {
MODULE = local.module
TOPIC_ARN = local.topic_arn
VERSION = local.payload_object_version
TWILIO_ACCOUNT_SID = var.twilio_account_sid
TWILIO_API_KEY = var.twilio_api_key
TWILIO_API_SECRET = var.twilio_api_secret
TWILIO_FROM_NUMBER = var.twilio_from_number
TWILIO_TO_NUMBER = local.my_phone_number
MSGBIRD_ACCESS_KEY = var.messagebird_access_key
TO_NUMBER = local.my_phone_number
}
}
......
import os
import twilio.rest # pylint: disable=import-error
import messagebird # pylint: disable=import-error
TWILIO_ACCOUNT_SID = os.environ["TWILIO_ACCOUNT_SID"]
TWILIO_API_KEY = os.environ["TWILIO_API_KEY"]
TWILIO_API_SECRET = os.environ["TWILIO_API_SECRET"]
TWILIO_FROM_NUMBER = os.environ["TWILIO_FROM_NUMBER"]
TWILIO_TO_NUMBER = os.environ["TWILIO_TO_NUMBER"]
MSGBIRD_ACCESS_KEY = os.environ["MSGBIRD_ACCESS_KEY"]
TO_NUMBER = os.environ["TO_NUMBER"]
# pylint: disable=unused-argument
def handler(event, context):
message = event["Records"][0]["Sns"]["Message"]
client = twilio.rest.Client(
TWILIO_API_KEY, TWILIO_API_SECRET, TWILIO_ACCOUNT_SID
)
client.messages.create(
body=message,
from_=TWILIO_FROM_NUMBER,
to=TWILIO_TO_NUMBER,
client = messagebird.Client(MSGBIRD_ACCESS_KEY)
client.messages_create(
message,
TO_NUMBER,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment