This is an opinionated setup that uses Terraform to manage an AWS Lambda function.
This is a Terraform configuration that manages the an AWS EKS stack. It will create the following resources:
- AWS Lambda Function: Lambda function using a Docker image to run code
- AWS S3 Bucket: Used to store the attachments for the Lambda Function
- AWS Policy: Allows the Lambda Function to access the S3 Bucket
- AWS ECR Repository: Used to store the Docker image for the Lambda Function
- Docker Image Build and Push to AWS ECR repository
This setup the Terraform CLI to manage the IllumiDesk stack using Terraform Workspaces.
Ensure you have the following installed on your local machine:
You must have an AWS account and provide your AWS Access Key ID and AWS Secret Access Key.
The values for AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
should be saved as environment variables on your workspace or they can be provided as variables in the *.tfvars
file.
- Copy the
example.tfvars
file to<environment>.tfvars
and update the values with your AWS credentials.
cp example.tfvars dev.tfvars
- Create and/or select a Terraform workspace.
terraform workspace new dev
- Initialize the Terraform configuration.
terraform init
- Plan the Terraform configuration (replace
<environment>
with the name of your environment):
terraform plan -var-file=<environment>.tfvars
- For the development environment:
terraform plan -var-file=dev.tfvars
- For the production environment:
terraform plan -var-file=prod.tfvars
- Apply the Terraform configuration.
terraform apply -var-file=dev.tfvars
From the tests/lambda_function
directory, run the following command to test the Lambda function with Boto3. Ensure that the ARN
value is exported with the LAMBDA_FUNCTION_ARN
environment variable before executing the test:
# example for development environment lambda function
export LAMBDA_FUNCTION_ARN=arn:aws:lambda:us-east-1:860100747351:function:app-dev-docker-lambda_handler
python test_lambda_with_arn.py
This should output a result similar to the following:
{'statusCode': 200, 'body': '{"result": {"a": 5, "b": 20}}'}