Sending messages to SNS from AWS Lambda

Поделиться
HTML-код
  • Опубликовано: 5 авг 2024
  • It’s a very common use case that a Lambda function subscribes to messages from an SNS topic. But it can also be useful to send messages from a Lambda function to an SNS topic. In this video we will learn how to do that.
    Timestamps:
    - Intro: 0:00​
    - Create SNS topic: 2:04
    - Write Lambda Function code: 2:47
    - Add IAM Policies: 4:38
    - Time for testing: 5:08
    Code example: github.com/endre-synnes/pytho...
    Boto3 SNS documentation: boto3.amazonaws.com/v1/docume...
    AWS SNS documentation: aws.amazon.com/sns/?whats-new...
    Subscribe button animation: touchtechnologyreview.com/sub...
    Follow me on Github: github.com/endre-synnes

Комментарии • 17

  • @marphr5630
    @marphr5630 2 года назад

    Very clear explanation! Thank you!

  • @jarraddenzel
    @jarraddenzel 2 года назад

    keep it up bro, you're reeeeally good at this :)

  • @user-te3bb4rs2e
    @user-te3bb4rs2e 2 года назад

    double like for this video, please. Very good explanation

  • @itsme1587
    @itsme1587 2 года назад +1

    please show the very beginning to end to end result with all details, it would be very helpful for beginners like me. Other than this I like your videos very much

    • @EndreSynnes
      @EndreSynnes  2 года назад

      Thank you for your feedback!😄
      I have taken some shortcuts in this video (like creating the lambda function), since I've covered that a few times in previous videos. I can for sure include this in future videos 😄.
      On the other hand if you ment making videos where I create more complete applications with multiple lambda functions, database and API gateway connections, I can do that as well at some point😄 Meanwhile I have already created some videos covering each of these topics separately in this playlist: ruclips.net/video/U5cTqgrO2Kc/видео.html&ab_channel=EndreSynnes

  • @tusharpathade7670
    @tusharpathade7670 Год назад

    Can we store SNS notifications into S3 bucket using lambda functions or somehow?

    • @EndreSynnes
      @EndreSynnes  Год назад

      Hi 😄 I guess you could do that. I suppose using your lambda function to save the SNS payload as a file in S3 could be one way of doing that. Then again what is the use case for this? I would assume it could be a better idea to store the SNS payload in a DynamoDB table if you for example want to access the content at a later point in time. 🤔 Then again this depends on your use case 😄

  • @reshmaa5724
    @reshmaa5724 Год назад

    Instead of adding the arn of the sns topic manually, is there a way to get it programatically within the lambda function and then publish the message?

    • @EndreSynnes
      @EndreSynnes  Год назад

      Hi, you need the ARN for sending messages to an SNS topic, using the boto3 library. To retrieve it programatically I guess you could use the list_topics function (boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns/client/list_topics.html ) to retreive a list of all topics and the ARN of each topic. Then again, you need to know the name of the topic anyways, and when you have that it's quite easy to construct the ARN from that, since all you need to know now is the region and account id where the topic is located.
      Either way I would suggest not hard coding the ARN in your lambda function code. Other options could be to store it in an SSM parameter (which you access in your lambda function) or injecting it as an environment variable if you deploy your lambda function and SNS topic using Infrastructure as Code.
      I hope this was somewhat helpful 😄

  • @santoshdutt3663
    @santoshdutt3663 Год назад

    Is it possible to use multiple SNS topics with one Lambda?

    • @EndreSynnes
      @EndreSynnes  Год назад

      Hi 😄
      I assume you mean sending to multiple SNS topics from one Lambda function?
      In that case, I haven't tried that myself, but I can't see any reason why you shouldn't be able to do that. I guess you could just use the Boto3 library as I have done here, and just send to multiple SNS topics. Then again what is the use case for this? Maybe EventBridge could be an alternative, with custom rules depending on the content of each message/record?

  • @lokanathpanda7187
    @lokanathpanda7187 8 месяцев назад

    Hello Sir, Sir I want to share the message the members those are present in the dynamDb table, there the phone number is available. Then please tell me what should the process that i should follow to send the message.

    • @EndreSynnes
      @EndreSynnes  7 месяцев назад

      Hi😄 Just to clarify; you have a DynamoDB table where the phone numbers are stored, and want to send SMS to each one of them?

    • @lokanathpanda7187
      @lokanathpanda7187 7 месяцев назад

      @@EndreSynnes Thank you for replying to me.
      Yes, I have a Dynamodb where the mobile numbers are stored. Using those numbers I want to send the Sms to those people whose details are available in the Dynamodb table. In the message I want to share some other information that is present in the Dynamodb table. For example: Hello Mr.Deo
      We got the subscription fee of 499 on 19/12/23.
      Thank you.
      So the above information need to be updated in the message these informations are stored in the database.
      Sir please tell if it is possible to do it in AWS.