Skip to content

rc-GeorgeAllen/terraform-lambda-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform + Golang AWS Lambda + API Gateway

This is a minimal Hello World example of deploying an HTTP API backed by an AWS Lambda function. The function is written in Go and deployment is automated with Terraform.

Prerequisites

Terraform and Go

Install Terraform and Go. On macOS with Homebrew:

$ brew install go terraform

AWS credentials

Configure your AWS access key and secret key with the aws configure command, or just create a file ~/.aws/credentials containing the keys:

[default]
aws_access_key_id = KEY
aws_secret_access_key = KEY

The access key ID and the secret access key can be generated in the AWS management console.

AWS region

The environment variable AWS_DEFAULT_REGION should be set to your favorite region. us-east-1 would just work if you are not sure:

$ export AWS_DEFAULT_REGION=us-east-1

This environment variable is used by the Terraform AWS provider.

Usage

Run make to build and deploy an API:

$ make

In the process Terraform will ask you for a confirmation, so type yes. Everything should finish in less than a minute! After this you can play with the API:

$ curl -fsSL $(terraform output -raw url)?name=world
Hello, world!
$ curl -fsSL $(terraform output -raw url)?name=lambda
Hello, lambda!

Cleanup:

$ make clean

About the Makefile

The Makefile is for convenience and does nothing special. It just runs following commands for you:

$ terraform init
$ go get .
$ GOOS=linux GOARCH=amd64 go build -o hello
$ zip hello.zip hello
$ terraform apply
$ terraform destroy

References

Lambda

API Gateway

Terraform

About

Hello World example of AWS Lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HCL 79.6%
  • Go 13.4%
  • Makefile 7.0%