Deploy Lambda function with Terraform

Deploy Lambda function with Terraform

In this post we will use Terraform to deploy a simple Lambda function written in Python. You can follow the video or continue reading.

Prerequisites

Clone the tutorial repository

Clone the tutorial repository from Github. Change to the newly created directory.

Initialize Terraform

terraform init

This will install and initialize the AWS Provider.

Deploy

terraform apply

This will package the Python handler and create the Lambda function.

Test

aws lambda invoke --function-name hello_lambda out.txt

This command invokes the Lambda function and should return with:

{
    "StatusCode": 200,
    "ExecutedVersion": "$LATEST"
}

The output is in the out.txt file and should be:

"Hello from Lambda!"

Delete

To delete all resources created use:

terraform destroy
comments powered by Disqus