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.
Install Terraform and Go. On macOS with Homebrew:
$ brew install go terraformConfigure 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.
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-1This environment variable is used by the Terraform AWS provider.
Run make to build and deploy an API:
$ makeIn 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 cleanThe 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