snsinfu
terraform-lambda-example
HCL

Hello World example of AWS Lambda

Last updated Apr 8, 2024
40
Stars
17
Forks
0
Issues
0
Stars/day
Attention Score
12
Language breakdown
HCL 79.6%
Go 13.4%
Makefile 7.0%
Files click to expand
README

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][terraform] and [Go][golang]. On macOS with Homebrew:

$ brew install go terraform

[terraform]: https://www.terraform.io/ [golang]: https://www.terraform.io/

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]
awsaccesskey_id = KEY
awssecretaccess_key = KEY

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

AWS region

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

$ export AWSDEFAULTREGION=us-east-1

This environment variable is used by the [Terraform AWS provider][terraform-aws].

[terraform-aws]: https://www.terraform.io/docs/providers/aws/

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

🔗 More in this category

© 2026 GitRepoTrend · snsinfu/terraform-lambda-example · Updated daily from GitHub