How To Trigger AWS Lambda by SMS

Did you know that you can trigger AWS Lambda via an SMS, with only AWS managed services?

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.

Customer Engagement

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!

Application Integration

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.

  • Click on create a topic.
  • Fill in the name for the topic and keep the default values the same.

  • We are done with SNS!

3- Prepare IAM Role for Lambda:

We will work with Lambda, and for that reason, let us make a proper role to consume SNS messages.

  • Open the IAM console and click on Roles.
  • Click on Create Role.
  • Select Lambda from the use cases list and click next.

  • In attach permission policies, search for SNS.
  • Choose Read-Only Access from the list.

  • Finish the steps by given the role a descriptive name.

4- Lambda Time!

Now, we can prepare the function that will consume the received SMS. Let’s start:

  • From Services, click on Lambda
  • In Dashboard, click on Create Function button.
Fill in the needed information and do not forget to select an existing role, which is the one we created

  • In the designer part, click on Add Trigger.

  • In trigger configuration, search for SNS and then look for the SNS topic we created earlier.

  • Done! This function will be triggered whenever SNS topic receives messages.

5- Pinpoint Configuration:

So, last step is here. Since we prepared all the resources, we need to configure the part the will trigger all the previous configurations.

  • From Services, click on Pinpoint.
  • On the Pinpoint main page, click on Manage Projects.
  • Create a new project.
  • Skip Project Features for now.
  • In Project Dashboard, click on Settings -> SMS and Voice.

  • In the SMS and voice page, under Number settings, click on the long/short code you have.

NOTE: This is the code you will get after you asked for in the first step.

  • Go all the way down until you see Two-way SMS. Click on it.
  • First thing, enable it.
  • In incoming messages destination, choose an existing SNS topic, and select the one we created earlier.

  • Done! easy right?

How to test?

So, you have everything in place and we need to trigger the function. Just send an SMS to the long/short code you have.

To validate that the function got triggered, check Lambda logs.

Any Useful Use-Case for This Event?

I was thinking, what benefit I will get from triggering Lambda this way, and I guess I have a pretty good reason.

Imagine that you have a marketing dashboard in an EC2 that gets turned off after working hours. One day, a colleague from the marketing department called you and asked you to turn it on for few hours as he has something urgent. Imagine with me opening your laptop if you have it with you, connect it to Wifi, open the console, log in, don’t forget you enabled MFA, ext… Why can’t you have a Lambda function that when you send a short SMS, will do the job for you! Of course, you can validate the number is yours when you try to trigger it.


AWS Lambda is really great innovation. It amazes me every time I try a new thing. Triggering a computing unit via SMS opens a whole new world of options and possibilities for sysadmins, businesses, and those who like fun projects like me.

We ZippyOPS, Provide consulting, implementation, and management services on DevOps, DevSecOps, Cloud, Automated Ops, Microservices, Infrastructure, and Security

Services offered by us:

Our Products:

Our Solutions:

For Demo, videos check out YouTube Playlist:

Relevant Blogs:

What Keycloak Is and What It Does? 

Is Windows 11 Safer Than Windows 10? 

Detect Proactively Whether Application’s Memory Is Under-allocated 

Questions on Monitoring: Before You Monitor

Recent Comments

No comments

Leave a Comment