Posts

Showing posts with the label Microservices

DynamoDB Streams

Image
  DynamoDB Streams are one of the most powerful—but often under‑explained—features in DynamoDB. A DynamoDB Stream captures every change to items in a table: INSERT MODIFY REMOVE You can then process these changes using: AWS Lambda Kinesis Custom consumers This is how you build event‑driven architectures with DynamoDB. Enable Streams on the Table: You choose a stream view type, e.g.: NEW_IMAGE → only the new item OLD_IMAGE → only the old item NEW_AND_OLD_IMAGES → both KEYS_ONLY → only keys I have table created by the name called " order ". I have enabled "Streams" to capture the changes to the table. And I have added the lambda function to process the streams. Lambda gets triggered , whenever there is a change in the DB items. Below is the lambda snippet: import json def lambda_handler(event, context):     for record in event[ "Records" ]:         event_name = record[ "eventName" ]         keys = record[ "dynamo...

APIGW + Lambda + DynamoDB

Image
  In this post, let see a demo application which is accessible by the users via API GW and the back end logic for the application is served by AWS lambda function. For persistent storage, we are using DynamoDB table. Lets start with DynamoDB table: I created a DynamoDB table by the name " employee_table ". Table has a primary key " employee_id " of datatype Number. So, any query to the table must be made through the key " employee_id ", else we need to scan the entire table. Let's add an item to the table from console. Now, we added an item to the table. Let's do the same and other action via API GW and Lambda Functions. Let's create a lambda function. One lambda function, based on the query parameter it invokes the function within the lambda. import json import boto 3 from botocore.exceptions import ClientError from decimal import Decimal from boto 3 .dynamodb.conditions import Key # Initialize the DynamoDB client dynamodb = boto 3 .resource(...

AWS Lambda Integration With EventBridge

Image
                                                                                  In our previous blog, we explored the concept of Lambda versioning. In real-world scenarios, Lambda functions are typically triggered either on a schedule or in response to specific events. In this post, we’ll walk through how to invoke a Lambda function using both scheduled triggers and event-driven mechanisms. This is our goal. Our lambda scans for any RUNNING, PENDING instances of type "T3.SMALL". If there are any instances of that type, it triggers an email. Involved services: 1) Lambda - Python code to scan for  RUNNING, PENDING instances of type "T3.SMALL" 2) Event Bridge - Scheduler and Event Based. 3) SNS - Notification Service. Here is the simple...