Welcome to your deployment task! This guide will walk you through the process of deploying AWS Lambda functions using Docker images with Terraform on LocalStack, and how to connect them to an API Gateway.
Your mission is to:
- Deploy a Lambda function using the
jonathanpick/first-lambda:v1
Docker image. Connect it to an API Gateway, invoke the function at its root path ("/"), note down the hint provided in the response. - Deploy a second Lambda function using the
jonathanpick/second-lambda:v1
Docker image. This time, connect it to the same API Gateway, invoke the function at its root path ("/"), and capture the secret provided in the response.
Ensure you have the following tools installed and configured:
- Docker & Docker Compose
- Terraform
- AWS CLI, configured to interact with LocalStack for local deployment
LocalStack mimics AWS cloud services locally, allowing you to test cloud applications without incurring costs. Use Docker Compose to spin up a LocalStack instance:
docker-compose.yml
version: '3.8'
services:
localstack:
image: localstack/localstack
ports:
- "4566:4566"
environment:
SERVICES: lambda,apigateway,iam,logs
DEBUG: 1
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
Run docker-compose up to start LocalStack.
Create Terraform configurations to deploy your Lambda functions and set up the API Gateway. You'll need to modify the provider settings to point to LocalStack. Deploying first-lambda with Terraform
Define your Lambda function in Terraform using the aws_lambda_function resource. Instead of specifying a ZIP file for the code, you'll use the image_uri attribute to point to the Docker image.
Example Terraform snippet:
resource "aws_lambda_function" "first_lambda" {
function_name = "firstLambdaFunction"
package_type = "Image"
image_uri = "jonathanpick/first-lambda:v1"
role = aws_iam_role.lambda_role.arn
}
Repeat the process for second-lambda.
Set up an API Gateway to trigger your Lambda functions. Use Terraform to define the API Gateway and connect it to your deployed Lambda functions.
After deployment, use the AWS CLI or any HTTP client to invoke your Lambda functions through the API Gateway. The invoke URL can be obtained from the Terraform output.
Create a Docker Compose file to automate:
Spinning up LocalStack.
Running a container to deploy your Terraform configurations.
A script to invoke your Lambda functions and display the secret.
Submission
Submit your completed project via a pull request to the designated repository, or as a ZIP file through the preferred channel. Support
If you encounter any issues or have questions, feel free to reach out for assistance.
Good luck, and we're excited to see your solutions!