Posts

Showing posts with the label System Design

Session ID vs Session Token

Image
  In this post  we will see what is a session token and session ID. Imagine, you are want to travel is a train and you buy a ticket. The ticket is valid for a certain amount of time. You can travel any number of times as long as the ticket is valid.  Ticket is the "Session Token". Let's compare with distribute systems. When you login to the banking website, it prompts the user to enter with "Username: and "Password". Upon successful authentication, the authentication server generates a session token. This session token is valid for a certain amount of time. With this token, the user can make future requests in the banking site like checking balance, fund transfer. Once the token is expired, the user must "Re-Authenticate". Then, What is Session ID? When a user log to the banking website, server create a session token post verifying credentials. Then, the server creates a session ID. Server stores the token inside the session data. Server gives the...

Deploying a Java Code using AWS EC2

Image
  In this post, we will see how to deploy the JAR on a EC2 instance with Auto Scaling Group with Load Balancer. We can do the same using AWS Code Deploy with orchestration using AWS Code Pipeline. We are taking a different path. In the previous post, https://rsinfomindss.blogspot.com/2026/04/aws-codebuild.html  Once the build is stored in the S3. We have to perform the below steps in a EC2 instance to run the code. 1)        Download Java. 2)        Create a folder for the application. 3)        Download the JAR from S3. 4)        Start the JAR. I will start with creating a Launch Template. Refer to https://rsinfomindss.blogspot.com/2023/04/aws-launch-template.html  Make sure IAM EC2 instance profile is create with the permission to download S3 objects (JAR) from the EC2 instance. Refer to example below. S3 bucket "demo-java-application-a...

AWS CodeBuild

Image
  AWS CodeBuild is a fully managed build service that compiles source code, runs tests, and produces software packages that are ready to deploy.   With CodeBuild, you don’t need to worry about provisioning and managing your own building infrastructure.   You simply provide your build project’s source code and build settings, and CodeBuild handles the rest. With AWS Code Deploy, you can avoid the manual process of deploying code, reduce the risk of errors and downtime, and improve the overall efficiency of your deployment process. For example, if you have a web application that you want to deploy , you can use CodeBuild to compile your source code, run unit tests, and produce a deployable package.   What is Buildspec file for Codebuild? The Buildspec file is a configuration file used by AWS CodeBuild to define how to build and deploy your application or software project. It is written in YAML or JSON format and contains ·     ...

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(...

API Gateway with AWS S3

Image
  In this post, we will see how to read objects from S3 using AWS API GW. I already have a bucket with a JSON file. Here is the lambda function for reading the object from the bucket. In the below code, I have hardcoded the bucket name and the object name. import json import boto3 client = boto3.client( 's3' ) def lambda_handler ( event , context ):     response = client.get_object(     Bucket = 'demo-001-first' ,-------------> Bucket Name     Key = 'bucket1.json' ,------------------> Object Name )     # convert from streaming to bytes     data_bytes = response[ 'Body' ].read()     #bytes to string     data_strings = data_bytes.decode( "UTF-8" ) # convert from strings to dict     data_dict = json.loads(data_strings)     return {         'statusCode' : 200 ,         'body' : data_dict     } Finally, I have my API GW (REST) as belo...