Adapted from Terraform tutorial Serverless Applications with AWS Lambda and API Gateway.
NOTE: this example does not set up a Lambda log group and is somehow configured such that AWS Lambda does not automatically create one.
-
Initialize the project:
$ terraform init
-
Deploy:
terraform apply
-
Set an environment variable for the API Gateway URL and curl some routes:
$ export BASE=$(terraform output base_url) $ curl $BASE/foo {"id":"foo","count":1} $ curl $BASE/foo {"id":"foo","count":2} $ curl $BASE/bar {"id":"bar","count":1}
To clean up resources, run terraform destroy
.