Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-load-balancer

serverless framework sample that shows how to deploy a load balancer (with vpc/subnet configuration) connected to a lambda in aws.

  • creates a LoadBalancer, HTTP Listener and Lambda
  • links the Listener and Lambda
  • stores the LoadBalancerDNSName (url) in ParameterStore

This feature has been introduced in v 1.45 and extended in 1.46 serverless framework

when to use load balancer instead of api gateway ?

Install Requirements

npm install serverless -g
npm install

Modify Config

Modify the file /config/serverless.config.yml

    VPC_ID: 'vpc-xxxxxxxxx'
    SUBNET_ID_A: "subnet-xxxxxxxxx"
    SUBNET_ID_B: "subnet-xxxxxxxxx"
    SUBNET_ID_C: "subnet-xxxxxxxxx"
    SCHEME: "internet-facing" or "internal" # load balancer scheme - 

Deploy solution

sls deploy

Result:

  1. Execute info to get load balancer url
sls info -v

you should get the full output containing the load balancer url.


Stack Outputs
LoadBalancerDNSName: serverless-load-balancer-258977035.eu-central-1.elb.amazonaws.com
HandlerLambdaFunctionQualifiedArn: arn:aws:lambda:eu-central-1:368555349508:function:serverless-load-balancer-dev-handler:1
ServerlessDeploymentBucketName: serverless-load-balancer-serverlessdeploymentbuck-16pgpyls1225e
  1. Paste the LoadBalancerDNSName Value into your browser or execute postman to set a GET statement against the URL.

Expected Response:

    Successfully executed lambda call via loadbalancer

Additional things to know

  • This sample does not care if the lambda and the load balancer are both in a vpc. It could be mixed in anyway dependent of the use case

  • The load balancer url will be stored as Parameter in Parameter store. This helps to reference the loadbalancer url easily tool-independent in other stacks.

About

serverless framework sample that shows how to combine a load balancer with a lambda

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.