Skip to content

easy-lamb/easy-lamb-terraform

Repository files navigation

Module Terraform Easy-Lamb

Allow use to easily deploy AWS Lambda functions with Terraform.

Features

  • Deploy AWS API Gateway
  • Associate Authorizer to API Gateway
  • Deploy AWS Lambda function
  • Bind AWS Lambda function to API Gateway
  • Bind AWS Lambda function to SQS queue
  • Bind AWS Lambda function to IoT rule
  • Bind AWS Lambda function to Cron event

Usage

As module

module "easy-lamb" {
  source = "URL"
  version = "LAST_RELEASE_VERSION"
  project_name = "easy-lamb-api"
  aws_region   = "eu-west-1"
  environment  = "prod"

  functions = [
    {
      name        = "get-user-data"
      memory      = 128
      timeout     = 30
      source      = "dist/get-user-data"
      handler     = "get-user-data.handler"
      runtime     = "nodejs18.x"
      http        = true
      http_method  = "GET"
      http_path    = "/users/{userId}"
      description = "Retrieve user data by user ID"
    }
  ]
}

As standalone

  • Clone the repository
  • Edit the file providers.tf
  • Create a file variables.tf based on the example below

Examples

Vous trouverez un exemple d'utilisation du module dans le répertoire examples.

Generated documentation

This documentation is generated using terraform-docs. Please do not edit it manually.

Requirements

Name Version
archive ~> 2.0
aws ~> 5.0
local ~> 2.1

Modules

Name Source Version
api_gateway ./modules/api_gateway n/a
cron ./modules/cron-lambda n/a
http ./modules/http-lambda n/a
iot ./modules/iot-lambda n/a
lambda ./modules/lambda n/a
sqs ./modules/sqs-lambda n/a

Inputs

Name Description Type Default Required
api_gateway api_gateway = {
cors = {
allow_origins = "The origins to allow"
allow_methods = "The methods to allow"
allow_headers = "The headers to allow"
}
authorizer = {
name = "The name of the authorizer"
audience = "The audience for the authorizer"
issuer = "The issuer for the authorizer"
identity_sources = "The identity sources for the authorizer"
}
log_retention = "The number of days to retain logs for"
}
object({
cors = optional(object({
allow_origins = optional(list(string), [""])
allow_methods = optional(list(string), ["GET", "POST", "PUT", "DELETE", "OPTIONS"])
allow_headers = optional(list(string), ["WebHook-Allowed-Origin", "Authorization", "Content-Type"])
}), {
allow_origins = ["
"]
allow_methods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
allow_headers = ["WebHook-Allowed-Origin", "Authorization", "Content-Type"]
})
authorizer = optional(list(object({
name = string
audience = optional(list(string))
issuer = optional(string)
authorizer_type = optional(string, "JWT")
function_name = optional(string)
identity_sources = list(string)
})), [])
log_retention = optional(number, 14)
})
n/a yes
aws_region The AWS region to deploy to string n/a yes
environment The environment to deploy to string n/a yes
functions functions = {
name = "the name of the function"
description = "The description of the function"
memory = "The amount of memory to allocate to the function (https://docs.aws.amazon.com/lambda/latest/dg/limits.html)"
timeout = "The amount of time the function has to run (https://docs.aws.amazon.com/lambda/latest/dg/limits.html)
source = "The path to the source code for the function (ex: dist/hello)"
handler = "The name of the handler function in the source code (ex: fileName.functionName)"
runtime = "The runtime to use for the function (https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime)"
http = "Whether the function is an HTTP function, if true bind to an HTTP API Gateway with values from httpMethod, httpPath and authorizer"
http_method = "The HTTP method to bind to the function (ex: GET)"
http_path = "The HTTP path to bind to the function (ex: /hello)"
authorizer = "The name of the authorizer to use for the function"
mqtt = "Whether the function is an MQTT function, if true bind to an MQTT topic with values from mqttSql"
mqtt_sql = "The MQTT SQL to bind to the function (ex: SELECT * FROM 'topic')"
sqs = "Whether the function is an SQS function, if true bind to an SQS queue
sqs_listeners = "The names of the SQS queues to bind to the function (ex: ['mysuper-function-name'])"
cron = "The cron expression to trigger the function (ex: 0 23 * * ? *)"
log_retention = "The number of days to retain logs for"
environment = "The environment variables to set for the function"
assume_roles = "The roles to assume for the function"
policies = "The policies to attach to the function"
override_env = "Read .env file and add values to environment"
}
list(object({
name = string
memory = number
timeout = number
source = string
handler = string
runtime = string
tracing = optional(bool, true)
http = optional(bool, false)
http_method = optional(string)
http_path = optional(string)
authorizer = optional(string)
mqtt = optional(bool, false)
mqttSql = optional(string)
sqs = optional(bool, false)
cron = optional(string)
description = optional(string)
environment = optional(map(string), {})
sqs_listeners = optional(list(string), [])
log_retention = optional(number, 3)
assume_roles = optional(list(string), [])
policies = optional(map(string), {})
override_env = optional(bool, false)
}))
n/a yes
output_zip_dir The directory to output the zip files to string "dist" no
project_name The name of the project string n/a yes

About

Terraform Module for deploying AWS Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages