GithubHelp home page GithubHelp logo

kenwoodjw / terraform-lambda-apigateway Goto Github PK

View Code? Open in Web Editor NEW

This project forked from serverless-projects/terraform-lambda-apigateway

0.0 3.0 0.0 175 KB

:fire: An example of a Python (AWS) Lambda exposed with API Gateway, configured with Terraform.

License: MIT License

Makefile 9.00% HCL 88.59% Python 2.41%

terraform-lambda-apigateway's Introduction

Hello (AWS) Lambda with Terraform

Build Status

This project is an example of a Python (AWS) Lambda exposed with API Gateway, configured with Terraform. This demo project is related to the following blog post: A Tour of AWS Lambda.

Introduction

This demo project creates a /hello endpoint with two methods (GET and POST). Both methods are bound to a single file containing two handlers (a.k.a. lambda functions, one for each method). This is defined by a handler parameter. The code for each lambda function is written in Python (method names are just a convention):

def handler(event, context):
    return { "message": "Hello, World!" }

def post_handler(event, context):
    return { "message": "I should have created something..." }

The Terraform configuration relies on two modules: lambda and api_method. See the Terraform Modules section for further information. This configuration creates two lambda functions on AWS Lambda, a (deployed) REST API with a single endpoint and two HTTP methods on API Gateway, and takes care of the permissions and credentials. The figure below is an example of what you get in the API Gateway dashboard:

Getting started

You must have an AWS account. Next, you must install Terraform first.

Clone this repository, then run:

$ make get

Create a terraform.tfvars file with the content below. This step is optional as Terraform will ask you to fill in the different values, but it is convenient.

aws_region     = "eu-west-1"

You are now ready to use Terraform!

$ make plan

If everything is OK, you can build the whole infrastructure:

$ make apply

You can destroy all the components by running:

$ make destroy

For more information, please read the Terraform documentation.

Terraform Modules

lambda

module "lambda" {
  source  = "github.com/TailorDev/hello-lambda/lambda"
  name    = "my-lambda"
  handler = "handler"
  runtime = "python2.7" # could be nodejs | nodejs4.3 | java8 | python2.7
  role    = "my-role"
}

Important: this module assumes that the source file, the lambda (in AWS), and the zip file have the same name. For example, we use hello_lambda in this project. The handler parameter distinguishes the different lambda functions that can be invoked.

api_method

module "hello_post" {
  source      = "github.com/TailorDev/hello-lambda/api_method"
  rest_api_id = "rest-api-id"
  resource_id = "resource-id"
  method      = "POST"
  path        = "resource-path"
  lambda      = "my-lambda"
  region      = "eu-west-1"
  account_id  = "account-id"
}

License

This project and its Terraform modules are released under the MIT License. See the bundled LICENSE file for details.

terraform-lambda-apigateway's People

Contributors

willdurand avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.