Use Function URL to send SMS in AWS

A use case for the AWS Lambda FunctionURL

Picture by Paul Hanaoka on Unsplash

Whats up, everybody. At this time we’re going to discuss concerning the new Perform URL function in Lambda. I used this new function in a bit challenge that I’ve been doing for a buyer that includes sending an SMS in AWS with a customized OTP.

The operate URL is a brand new function from AWS Lambda that permits an HTTPS URL to invoke a Lambda operate. While you create a operate URL, Lambda generates an distinctive URL endpoint, like this one:

https://<url-id>.lambda-url.<area>.on.aws

What’s the distinction between Lambda Perform URL and API Gateway?

When you don’t want the superior options from API Gateway, equivalent to caching, stage, throttling, or auth, however simply an endpoint to invoke your lambda, you should utilize the primary one as a substitute.

You gained’t be capable of handle the standing code, however you may arrange the CORS for the operate URL.

Each time you name a operate URL, there may be an invocation of Lambda.

For that reason, the operate URL is sweet for a webhook, a service the place you don’t have to cache the results of a service that should do an instantaneous motion, like ship an SMS.

For this challenge, I exploit SNS to ship an SMS with an OTP message.

Amazon Easy Notification Service (Amazon SNS) is a managed service that gives message supply from publishers to subscribers.

SNS has many channels to ship notifications like emails, push notifications, SMS, and so on. The service could be very low cost ($0.50 per million requests), however the SMS service has an extra price and it’s totally different per nation.

Find out how to exit Sandbox mode

The SMS service has the sandbox mode, so you may ship SMS solely to verified numbers. If you wish to exit it, it’s a must to open a help case from the AWS console.

To take action, you want some data like “kind of communication,” “nation,” “spent restrict for the month,” and so on. And a few hours after submitting, it is possible for you to to ship SMS in every single place.

Within the SAM Template, I’ve enabled the operate URL within the Lambda operate:

SendSmsFunction:
Sort: AWS::Serverless::Perform
Properties:
CodeUri: ./src
Runtime: nodejs14.x
Handler: index.handler
Architectures:
— arm64
FunctionUrlConfig:
AuthType: NONE
Insurance policies:
Assertion:
— Sid: Sns
Impact: Enable
Motion:
— sns:Publish
Useful resource:
— “*”

And right here is the code to ship the SMS with AWS SNS:

That’s all for at present.

Thanks for studying.

Wish to Join?Don’t neglect to take a look at the other articles on my web site.

More Posts