Posts

Showing posts with the label Amazon Web Services

Update dynamodb items programatically

Today, I wanted to update all dynamodb items and couldn't find a handy example in AWS documentation.  Below is a handy script that I created to update all the dynamodb table rows with current time stamp using python from __future__ import print_function # Python 2/3 compatibility import boto3 import json import decimal from boto3.dynamodb.conditions import Key, Attr import datetime, time row = 0 table_name = 'table' dynamodb = boto3.resource('dynamodb') table = dynamodb.Table(table_name) # Helper class to convert a DynamoDB item to JSON. class DecimalEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): if o % 1 > 0: return float(o) else: return int(o) return super(DecimalEncoder, self).default(o) def updateItem(item): global row response = table.update_item( Key=item, UpdateExpression='SET #s = :updated', Expre...

Tracing Requests in AWS Serverless Applications

Image
Operating Serverless APIs using Amazon API Gateway, AWS Lambda and Microservices (running in ECS) can be bit challenging if logging is not given any forethought. Best practice is to decide in while designing the application what needs to be logged, how the log messages can be correlated and finally where is it should be sent for aggregation.  Its difficult to reconcile log events for a serverless API sent across multiple layers of application stack using CloudWatch log groups and log streams. Tracking down logs for a specific request or tailing request logs for a specific request can sometimes be a cumbersome experience.  Debugging for a specific issue or Tracing a specific request can be made easy by using the x-amzn-requestid and x-amzn-trace-id that comes for free when using AWS API Gateway. Its easy to leverage these Ids and keep track of your request.   In the following deployment diagram  How to capture the request ID for a particular API req...