GithubHelp home page GithubHelp logo

apigw_lambda's Introduction

API Gateway + Lambda

A terraform module to provision API infrastructure using API Gateway and Lambda.

Usage

# A basic IAM role
resource "aws_iam_role" "api_execution" {
  name = "${var.api_name}_api_execution"

  assume_role_policy = jsonencode(assume_role_policy = jsonencode(
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "",
          "Action": "sts:AssumeRole",
          "Principal": {
            "Service": [
              "apigateway.amazonaws.com",
              "lambda.amazonaws.com"
            ]
          },
          "Effect": "Allow"
        }
      ]
    }
  )
}

# A basic policy that enables logging
resource "aws_iam_role_policy" "api_execution" {
  name = "${var.api_name}_api_execution"
  role = aws_iam_role.api_execution.id

  policy = jsonencode(
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "logs:CreateLogGroup",
            "logs:CreateLogStream",
            "logs:PutLogEvents"
          ],
          "Resource": [
            "arn:aws:logs:*:*:*"
          ]
        }
      ]
    }
  )
}

module "api" {
  source = "[email protected]:abehoffman/apigw_lambda.git"

  # the name of the api
  api_name = <api_name>

  # the Amazon Resource Name (arn) of the execution role
  api_iam_role_arn = <aws_iam_role.api_execution.arn>

  # The s3 bucket the package is stored in for retrieval by lambda
  packages_bucket = <packages_bucket>

  # The key of the package
  package_key = <package_key>
}

This will create an API Gateway instance that invokes the lambda function running your package code. It also, by default provides logging infrastructure. Under the hood, it uses terraform-aws-api-gateway-enable-cors to provide CORS.

Configuration

api_name: the name of the api (will be the name used by AWS to describe the infrastructure)

api_iam_role_arn: the Amazon Resource Name (arn) of the associated IAM role. At a minimum, this role needs to allow the invocation of API Gateway and Lambda AWS services as seen above.

packages_bucket: The name of the s3 bucket the package is stored in for retrieval by lambda.

package_key: The key of the package to be retrieved by Lambda.

Outputs

invoke_url: the API gateway invoke url

apigw_lambda's People

Contributors

abehoffman avatar

Stargazers

Ben Allan-Rahill avatar

Watchers

 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.