Skip to content

Files

Latest commit

 

History

History

terraform

Serverless API on Terraform

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.

Setup

  1. Install Terraform

  2. Configure AWS credentials.

  3. Initialize the project:

    $ terraform init
    
  4. Deploy:

    terraform apply
    
  5. 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}    

Cleanup

To clean up resources, run terraform destroy.