Skip to main content

Lambda framework for AWS

Project description

AWS-ALB-lambda-python

Framework for load-balancer and lambda function.

To learn more about writing AWS Lambda functions in python, go to the official documentation

Blogs about AWS lambda and python is here

Maintenance serverless Pyhton-Lambda-Doc made-with-python PyPI version fury.io PyPI pyversions Documentation Status Documentation Status Pyhton Lambda Build Status

Getting Started

This is the AWS lambda framework written in python. When the lambda function is triggered by ALB or API-Gateway the event variable that contain all the required info will be sent to the init function. By default this init function will be in lambda_function.py and the name will be lambda_handler. This framework contains the code from which you can call the functions that are required according to the path given the request.

This source code contain the following files:

  • lambda_function : Contains the code that will be triggered by ALB or API-Gateway etc.
  • request : Contains the request object which is created from the event that is send as an input.
  • response : Contains the object that should be sent back from lambda function to ALB.
  • lambda_mapping : Is the file that contain the mapping for the routes. Add your routes in here.
  • all_functions : Contain the function contains the respective code that can be used for the given path.
  • test_LambdaHandler : Contains the test code that can be usedfortesting all the functions.
## lambda_function.py

import lambda_function as lf

EVENT_FROM_ALB = {  "body": u"", 
	u"requestContext": 
	{u"elb": 
		{
			u"targetGroupArn": u"arn:aws:elb:ap-region-1:11:targetgroup/FROM_TARGET-GROUP/abc"
		}
	}, 
	u"queryStringParameters": {"a":1}, 
	u"httpMethod": u"GET", 
	u"headers": 
	{
		u"via": u"2.0 test.cloudfront.net (CloudFront)", 
		u"accept-language": u"en-US,en;q=0.5", 
		u"cloudfront-viewer-country": u"IN", 
		u"accept": u"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
		u"upgrade-insecure-requests": u"1", 
		u"cloudfront-is-mobile-viewer": u"false", 
		u"accept-encoding": u"gzip, deflate, br", 
		u"x-forwarded-port": u"443", 
		u"user-agent": u"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/", 
		u"cache-control": u"no-cache", 
		u"te": u"trailers", 
		u"cloudfront-is-desktop-viewer": u"true", 
		u"cloudfront-is-smarttv-viewer": u"false", 
		u"x-forwarded-for": u"192.168.1.1, 1.1.1.1", 
		u"x-amzn-trace-id": u"Root=1-5c0a5a83-123344", 
		u"host": u"clib.fyers.in", 
		u"x-forwarded-proto": u"https", 
		u"x-amz-cf-id": u"abc==", 
		u"pragma": u"no-cache", 
		u"connection": u"Keep-Alive", 
		u"cloudfront-is-tablet-viewer": u"false", 
		u"cloudfront-forwarded-proto": u"https"
	}, 
	u"path": u"/Some_ramdom_path/345/", 
	u"isBase64Encoded": False
}

RESOURCE_PREFIX = ""
EVENT_FROM_ALB["path"]= RESOURCE_PREFIX+'/abc'
EVENT_FROM_ALB["httpMethod"] = "GET"

resp = lf.lambda_handler(event=EVENT_FROM_ALB,context= "some_context")
print(resp)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_lambda-1.1.3.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

py_lambda-1.1.3-py3-none-any.whl (12.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page