DEV Community

Deep Dive on Writing and Reading Data to DynamoDB Table from Lambda Functions Using AWS Cloud Map Service Discovery

“ I have checked the documents of AWS to get into deep dive on writing and reading data to dynamodb table from lambda functions using aws cloud map service discovery. In terms of cost, need to pay for aws cloud map service, amazon cloudwatch, aws lambda and amazon dynamodb.”

AWS Cloud Map is a fully managed solution that you can use to map logical names to the backend services and resources that your applications depend on. It also helps your applications discover resources using one of the AWS SDKs, RESTful API calls, or DNS queries. AWS Cloud Map serves only healthy resources, which can be Amazon DynamoDB tables, Amazon Simple Queue Service queues, any higher-level application services that are built using Amazon Elastic Compute Cloud instances or Amazon Elastic Container Service tasks and more. Components of AWS Cloud Map as Namespace, Service and Service Instance.

In this post, you will experience how to deep dive on writing and reading data to dynamodb table from lambda functions using aws cloud map service discovery. Here I have created an aws cloud map, amazon dynamodb, aws lambda, cloudwatch and iam role.

Architecture Overview

Image description
The architecture diagram shows the overall deployment architecture with data flow, aws cloud map, amazon dynamodb, iam role and aws lambda.

Solution overview

The blog post consists of the following phases:

  1. Create of Amazon DynamoDB with Required Configurations and IAM Role with Required Permissions
  2. Create of AWS Cloud Map with Required Configurations and Register the Service Instance with Dynamodb and Lambda
  3. Output of Creating and Running Client Application Using AWS CloudShell

Phase 1: Create of Amazon DynamoDB with Required Configurations and IAM Role with Required Permissions

  1. Open the console of Amazon DynamoDB, create a table with required configuration as table name, partition key, key type and default table settings. Also create an IAM role as trust relationship for lambda with power user access permissions.

Image description

Image description

Image description

Image description

Image description

Image description

Phase 2: Create of AWS Cloud Map with Required Configurations and Register the Service Instance with Dynamodb and Lambda

  1. Open the console of AWS Cloud Map, create a namespace with name, description and instance discovery with api calls option. In the namespace, create a service named “data-service” with default configuration. Once the service is created, register the service instance with it including instance type, service instance id and custom attributes parameters. Here while service registers in service, keep the dynamodb table name created above in the custom attribute option.

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

  1. Create a lambda as a write function with required configuration and use values in code as namespace name, service name and query parameter. Similarly, create a service and register it with lambda created as a write function.

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

  1. Create a lambda as a read function with required configuration and use values in code as namespace name, service name and query parameter. Similarly, create a service and register it with lambda created as a read function.

Image description

Image description

Image description

Image description

Image description

Phase 3: Output of Creating and Running Client Application Using AWS CloudShell

Image description

Image description

Image description

Image description

Image description

Clean-up

Delete of AWS Cloud Map, Amazon Dynamodb, AWS Lambda, CloudWatch and IAM Role.

Pricing

I review the pricing and estimated cost of this example.

Cost of AWS Cloud Map = $1.0 per million API calls + $0.10 per resource-month = $(1x8) + $(0.10x0.002) = $8.0002

Cost of Amazon Cloudwatch = $0.0

Cost of AWS Lambda = $0.0

Cost of Amazon Dynamodb = $0.0

Total Cost = $8.0002

Summary

In this post, I showed “how to deep dive on writing and reading data to dynamodb table from lambda functions using aws cloud map service discovery”.

For more details on AWS Cloud Map, Checkout Get started AWS Cloud Map, open the AWS Cloud Map console. To learn more, read the AWS Cloud Map documentation.

Thanks for reading!

Connect with me: Linkedin
Image description

Top comments (3)

Collapse
 
marcosbelorio profile image
Marcos Belorio

Thanks for sharing, but the images are so small that is not possible to read.

Collapse
 
bhatnagargargee profile image
GargeeBhatnagar

Hi Marcos ! Thankyou for reading the blog. You can enlarge the image once you open any of it.

Collapse
 
marcosbelorio profile image
Marcos Belorio

I tried, but still not possible to read, unfortunately