Automate text Message(SMS) notification using SNS and AWS lambda

Introduction:
Automating SMS notifications using AWS Lambda and SNS (Simple Notification Service) is a powerful way to keep users informed about important events or updates in your application. AWS Lambda allows you to run code without provisioning or …


This content originally appeared on DEV Community and was authored by Rashmitha v

Introduction:
Automating SMS notifications using AWS Lambda and SNS (Simple Notification Service) is a powerful way to keep users informed about important events or updates in your application. AWS Lambda allows you to run code without provisioning or managing servers, while SNS enables you to send messages to a large number of recipients simultaneously.

working:
It is a source where the file is uploaded, this s3 bucket is configurated to trigger AWS lambda. lambda contains a python code which which perform event reading mechanism and publish the fully framed messages to SNS topic.To the SNS topic we will make phone and become a subscriber to the SNS topic and msg is publishes that text will receive about the event.

Architecture

Image description

  1. AWS Amazon S3:
  • provide the name to the bucket.
  • create a bucket.

Image description

2.create a lambda function

  • provide the function name.
  • use the runtime as python 3.9
  • use the existing role

Image description

to change the setting click the configurations

  • change the memory size
  • change the timeout to reduce the cost
  • click save

Image description

  • click trigger
  • add trigger select 's3 bucket'
  • click event types and select "all object create events".
  • click add

Image description

paste the lambda code in the code source.

import boto3

topic_arn = ""
def send_sns(message, subject):
    try:
        client = boto3.client("sns")
        result = client.publish(TopicArn=topic_arn, Message=message, Subject=subject)
        if result['ResponseMetadata']['HTTPStatusCode'] == 200:
            print(result)
            print("Notification send successfully..!!!")
            return True
    except Exception as e:
        print("Error occured while publish notifications and error is : ", e)
        return True

def lambda_handler(event, context):
    print("event collected is {}".format(event))
    for record in event['Records'] :
        s3_bucket = record['s3']['bucket']['name']
        print("Bucket name is {}".format(s3_bucket))
        s3_key = record['s3']['object']['key']
        print("Bucket key name is {}".format(s3_key))
        from_path = "s3://{}/{}".format(s3_bucket, s3_key)
        print("from path {}".format(from_path))
        message = "The file is uploaded at S3 bucket path {}".format(from_path)
        subject = "Processes completion Notification"
        SNSResult = send_sns(message, subject)
        if SNSResult :
            print("Notification Sent..") 
            return SNSResult
        else:
            return False
  • deploy the code and test the code.

3.create the SNS topic

  • click the standard SNS topic.
  • provide a name to the SNS topic.
  • create a topic

Image description

arn code is generated this code is pasted in the lambda function before deploying and testing the code.

4.create subscribers:

  • provide the ARN
  • select the protocol(SMS)
  • SNS endpoint - phone number
  • click on text messages(SMS)

Image description

  • click add phone number in - 'sandbox destination phone number'
  • add phone no. , select the country and verify.

Image description

the phone is number is verified.

Image description

  1. Subscribe Phone Numbers:
  • create subscription

Image description

  • choose topic.
  • select sms phone number appears after verification.

Image description

upload a dummy file to the trigger point i.e S3 and notification pops as a text message sent to phone.

Image description


This content originally appeared on DEV Community and was authored by Rashmitha v


Print Share Comment Cite Upload Translate Updates
APA

Rashmitha v | Sciencx (2024-07-13T20:23:05+00:00) Automate text Message(SMS) notification using SNS and AWS lambda. Retrieved from https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/

MLA
" » Automate text Message(SMS) notification using SNS and AWS lambda." Rashmitha v | Sciencx - Saturday July 13, 2024, https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/
HARVARD
Rashmitha v | Sciencx Saturday July 13, 2024 » Automate text Message(SMS) notification using SNS and AWS lambda., viewed ,<https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/>
VANCOUVER
Rashmitha v | Sciencx - » Automate text Message(SMS) notification using SNS and AWS lambda. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/
CHICAGO
" » Automate text Message(SMS) notification using SNS and AWS lambda." Rashmitha v | Sciencx - Accessed . https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/
IEEE
" » Automate text Message(SMS) notification using SNS and AWS lambda." Rashmitha v | Sciencx [Online]. Available: https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/. [Accessed: ]
rf:citation
» Automate text Message(SMS) notification using SNS and AWS lambda | Rashmitha v | Sciencx | https://www.scien.cx/2024/07/13/automate-text-messagesms-notification-using-sns-and-aws-lambda/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.