Deploy AWS Lambda functions with Terraform

- Tuesday, March 5, 2019

I built a GitHub project to explore and document some basic Terraform scripts, both to learn Terraform, and to figure out how to deploy to AWS Lambda without using serverless or the web UI.

Python Lambda function

The actual Lambda function is just a simple python function, but it’s instructive in that it shows how to structure the function return value to succeed:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import json


def handler(event, context):
    print("Incoming event: " + json.dumps(event, indent=2))
    return {
        'statusCode': 200,
        'headers': {
            'Content-Type': 'text/html'
        },
        'body': '<h1>It Worked</h1>'
    }

Makefile techniques

Also, the Makefile shows a couple interesting techniques to capture and test dynamically deployed Lambda functions.

AWS Terraform Tip
Software