Posts

Showing posts with the label API

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

AWS - ALB HTTP Customization

Image
  One of the advantages of ALB which operates on layer 7 is the ability to make customization on the HTTP layer. Let see with some examples. I have a ALB with target group serving HTTP traffic. Let’s start with adding a rule to the ALB listener. Give the rule name. Add the condition.  I am adding a “Path” based condition. If someone access by ALB DNS name with /login -> http://demo-lb-571503325.us-east-1.elb.amazonaws.com/login then what should I do? For every condition we can selection 1 action from 3 actions. Since I did not configure anything on /login. I am going to return with a fixed response like “HTTP 500 – No login method configured”. Let’s test it.