How To: Send Email Using Lambda & AWS SES (2 Min)

Описание к видео How To: Send Email Using Lambda & AWS SES (2 Min)

In this tutorial, you'll learn how to send an email using a Lambda function with the help of AWS SES (Simple Email Service).


Facebook:   / gokcedbsql  

Video Transcript:

Hi guys, this is Abhi fromGokcedb. In this video, you are going to learn how to send an email using a Lambda function, using the AWS SES Service. Let’s start by searching for SES in the AWS Console.

Next, hit Create Identity and choose the email address for Identity Type. Enter your email address then click on the Create Identity button. Now go to your inbox to verify your email address then refresh this page.  

Next, go to the AWS Console page and search for IAM which stands for identity and Access Management. Click on roles in the left menu then hit the create role button. Select Lambda and click on next.  

Search for then select Amazon SES Full and hit access. Give this role a name then clicks on Create Role.  Go back to the AWS Console and this time search for Lambda.

Click on Create function then give it a name. For runtime, I’m going to select Python and for the Default Execution role, I’m going to select the role that we just created. In the Code Source section, I’m going to copy-paste pre-written Python Code.  

On line 2, I’m importing theboto3 library which is the SDK for AWS. On line 5, I’m defining the SES Client as an online eight, I’m constructing the email subject and the body.  

Online nine, I’m using the send underscore email method to send an email. Next, click on deploy and then hit the test button. Give your test event a name then hit same.

Click on the test button again to test your Lambda function. Looks like the function worked as expected and I can see a new email in my inbox.  There you have it.

Make sure you like, subscribe, and turn on the notification bell. Until next time.

import json
import boto3

def lambda_handler(event, context):
client = boto3.client("ses")
subject = "test subject from lambda"
body = "test body from lambda"
message = {"Subject": {"Data": subject}, "Body": {"Html": {"Data": body}}}
response = client.send_email(Source = "[email protected]",
Destination = {"ToAddresses": ["[email protected]"]}, Message = message)
return response

Комментарии

Информация по комментариям в разработке