From f0b18892269bde16c4a9e993c0dc54d7e33e0989 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Fri, 7 Jan 2022 00:44:00 +0200 Subject: [PATCH] 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. --- requirements.txt | 2 +- sms-notify.tf | 19 ++++--------------- src/sms_notify.py | 20 +++++++------------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/requirements.txt b/requirements.txt index 35dd243..65499b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ dnspython +messagebird requests -twilio diff --git a/sms-notify.tf b/sms-notify.tf index 62a167b..7113427 100644 --- a/sms-notify.tf +++ b/sms-notify.tf @@ -1,13 +1,5 @@ -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 } } diff --git a/src/sms_notify.py b/src/sms_notify.py index 4564f2d..5c2391f 100644 --- a/src/sms_notify.py +++ b/src/sms_notify.py @@ -1,24 +1,18 @@ 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, ) -- GitLab