How To Trigger AWS Lambda by SMS
Did you know that you can trigger AWS Lambda via an SMS, with only AWS managed services?
Join the DZone community and get the full member experience.Join For Free
In my last article, I had placed a teaser that whether you can trigger Lambda by SMS. Today, We are going to do that! I am really excited to share this with you.
NOTE: This article’s resources are not fully covered in the free tier. Also, you cannot do it directly as there are some resources you will have to raise a ticket to get and adjust services limitations.
So, I have been waiting for over a month to finish this article and I postponed it because of the workload that we faced with working remotely and waiting to get the ticket resolved by the AWS support team. Which by the way, they were really helpful even in the free plan support.
What are the involved parts?
There are three main parts involved in this event, Customer Engagement, Application Integration, and compute services to make this happen.
Since we want to trigger a function via SMS, you will need a service or tool to get information from the user. Otherwise, how the function will get triggered?
In this part, we will use AWS Pinpoint. This service enables you to engage with customers through different channels like emails and transactional SMSs. Also, you can validate phone numbers if they are real too!
We are working with SMS, which leads us to work with SNS. SNS is a service that enables you to organize and manage SMS processes. Also, it can trigger Lambda too. You get the idea, right?
Since we want to do some computing processes for the SMS content, we will need a computing unit. The best and cheapest option is Lambda. Which is the reason for this article.
In a straightforward scenario, We will contact Pinpoint through SMS, the message will be passed to SNS, which will be responsible for triggering Lambda. No rocket science here.
I am here to show you how-to not to describe the theory behind it. So, shall we begin?
1- Request a Long/Short Code From Pinpoint
Since we want to send an SMS to Pinpoint, it is required to have a code. To obtain one, please follow the steps from the documentation here.
One point I want to bring attention to is some countries has both short and long code. But, as happened for me, which living in the Kingdom of Bahrain, we have only a long code, so far.
NOTE: It took a while for me to get the code as I was a basic support plan user and there is no default, fast way to obtain this code in my region. Apply for it in advance.
2- Create SNS Topic To Handle Pinpoint Messages
As we mentioned in the beginning, there is no way to invoke Lambda directly from Pinpoint, creating an SNS topic is a must for this purpose.
- From Services, look for SNS and click on it.
- Open SNS console and from the left panel, select topics.
Opinions expressed by DZone contributors are their own.