Using Lambda Function with Amazon DynamoDB


  1. Create a table in DynamoDB with a primary key
  2. Create a role that will have permission to work with DynamoDB and AWS Lambda.
  3. Create a function in AWS Lambda
  4. AWS Lambda Trigger to send mail
  5. Add data in DynamoDB
  1. Creating a table called the customer in Dynamodb table and how to enter data in that table.
  2. Triggering AWS Lambda function once the data is entered and sending mail using Amazon SES service.

AWS Lambda Trigger to Send Mail

Sending an email

var aws = require('aws-sdk'); 
var ses = new aws.SES({
region: 'us-east-1'
exports.handler = function(event, context, callback) {
let tabledetails = JSON.parse(JSON.stringify(event.Records[0].dynamodb));
let customerid = tabledetails.NewImage.cust_id.S;
let name =;
let address = tabledetails.NewImage.address.S;
var eParams = {
Destination: {
ToAddresses: [""]
Message: {
Body: {
Text: {
Data: "The data added is as follows:\n CustomerId:"+customerid+"\n Name:"+name+"\nAddress:"+address
Subject: {
Data: "Data Inserted in Dynamodb table customer"
Source: ""
console.log('===SENDING EMAIL===');
var email = ses.sendEmail(eParams, function(err, data) {
if (err) console.log(err);
else {
console.log("===EMAIL SENT==="); console.log("EMAIL CODE END");
console.log('EMAIL: ', email); context.succeed(event);
callback(null, "email is send");

Add Data in DynamoDB




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Developer Day — An opportunity to innovate at a time when nobody wants to take risks

How TiDB Improves Opera’s Ads Business

Test inference of yolov5 on a aws ec2 instance

Parallelize and Accelerate Your Pandas DataFrames

How To Check Open(Assigned) Notifications of a User in Oracle Fusion?

Beginner C#: Getting Started

How Web Developers Can Beat Perfectionism

How to generate multiple progress bars in a Flask App

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Building a great microservice with AWS Lambda doesn’t have to be hard

AWS Lambda for Data Scientists

Recommendation: Should AWS provide a function for lambda timeout

How to Pull Data from an API, Using AWS Lambda