jenspapenhagen / tf-lambda-api-gateway-example

example of using terraform to deploy a lambda function behind an api gateway

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tf-lambda-api-gateway-example

example of using terraform to deploy a node.js lambda function behind an AWS API Gateway

Installing

Prereqs:

  • node v8+
# clone this repository
$ git clone https://github.com/cludden/tf-lambda-api-gateway.git

# install dependencies
$ cd tf-lambda-api-gateway && npm install

Testing

Prereqs:

  • node v8+
# run the test suite
$ npm run test

Building

Note: this project uses features from from Node 8, and as such requires a build step

Prereqs:

  • node v8+
# run webpack which runs transpilation/minification and generates an
# artifact for each lambda function in the ./dist directory
$ npm run build

Deploying

Prereqs:

  • Terraform v0.12+
  • AWS account with high degree of privileges and credentials available in the environment
# change into the terraform directory
$ cd terraform

# create a new terraform environment
$ terraform env new dev

# install any missing plugins
$ terraform init

# run a plan
$ terraform plan -var env=dev
...
Plan: 13 to add, 0 to change, 0 to destroy.

# apply
$ terraform apply -var env=dev
...
Apply complete! Resources: 13 added, 0 changed, 0 destroyed.

Outputs:

url = https://<api_id>.execute-api.us-west-2.amazonaws.com/example_lambda_dev

# destroy when finished
$ terraform destroy -var env=dev

Note: it can take a few minutes before the integrations become active

License

Copyright (c) 2017 Chris Ludden Licensed under the MIT License

About

example of using terraform to deploy a lambda function behind an api gateway

License:MIT License


Languages

Language:JavaScript 55.8%Language:HCL 44.2%