AWS API Gateway is a great tool to use with Lambda. However, sometimes API Gateway can be quite expensive. If you are using API Gateway just as a proxy to lambda, and you have quite a large number of requests comes in, you can use AWS Load balancer with Lambda as the target.
In this repository, using Terraform, you can deploy a sample application with ALB and Lambda as the target.
- New VPC
- Two Subnets
- Internet Gateway
- Route Table with IGW attached (Here default route table is used)
- Application Load Balancer
- Security Group for ALB
- Placement Group
- Lambda function
- Add Lambda as a target in placement group.
-
Clone the repository.
-
Change permission of deploy.sh
chmod 775 deploy.sh
- Run
./deploy.sh
-
This will download necessary packages and create above resources upon your confirmation.
-
You may access the system using the output value
lb_address
By default ALB's termination policy is set to true
which will prevent delete it. So, first needs to set it as false.
In the terraform.tfvars file set the ALB_DELETION_PROTECTION
value to false
To apply the change, run
terraform plan -out tfout.plan
terraform apply tfout.plan
And to destroy the stack, run
terraform destroy