Home

Awesome

terraform-aws-lambda-auto-package

Github Actions Releases

Terraform Module Registry

A terraform module to define a lambda function which source files are automatically built and packaged for lambda deployment.

Features

Create a lambda function with the following supports.

Usage

module "lambda" {
  source  = "nozaq/lambda-auto-package/aws"

  source_dir  = "${path.module}/source"
  output_path = "${path.module}/source.zip"

  build_triggers = {
    requirements = "${base64sha256(file("${path.module}/source/requirements.txt"))}"
    execute      = "${base64sha256(file("${path.module}/pip.sh"))}"
  }
  build_command = "${path.module}/pip.sh ${path.module}/source"

  iam_role_name_prefix = "example-lambda-role"

  function_name = "example-lambda"
  handler       = "main.handler"
  runtime       = "python3.7"

  environment = {
    variables = {
      EXAMPLE_VAR = "foobar"
    }
  }
}

Check examples for non-python examples.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Requirements

NameVersion
<a name="requirement_terraform"></a> terraform>= 0.15.0
<a name="requirement_archive"></a> archive>= 2.2.0
<a name="requirement_aws"></a> aws>= 3.50.0
<a name="requirement_null"></a> null>= 3.1.0

Providers

NameVersion
<a name="provider_archive"></a> archive>= 2.2.0
<a name="provider_aws"></a> aws>= 3.50.0
<a name="provider_null"></a> null>= 3.1.0

Inputs

NameDescriptionTypeRequired
<a name="input_function_name"></a> function_nameA unique name for your Lambda Function.stringyes
<a name="input_handler"></a> handlerThe function entrypoint in your code.stringyes
<a name="input_output_path"></a> output_pathA path to which the source directory is archived before uploading to AWS.stringyes
<a name="input_runtime"></a> runtimeThe identifier of the function's runtime.stringyes
<a name="input_source_dir"></a> source_dirA path to the directory which contains source files.stringyes
<a name="input_allowed_services"></a> allowed_servicesA list of AWS Services that are allowed to access this lambda.list(string)no
<a name="input_build_command"></a> build_commandThis is the build command to execute. It can be provided as a relative path to the current working directory or as an absolute path. It is evaluated in a shell, and can use environment variables or Terraform variables.stringno
<a name="input_build_triggers"></a> build_triggersA map of values which should cause the build command to re-run. Values are meant to be interpolated references to variables or attributes of other resources.map(string)no
<a name="input_dead_letter_config"></a> dead_letter_configNested block to configure the function's dead letter queue.<pre>object({<br> target_arn = string<br> })</pre>no
<a name="input_description"></a> descriptionDescription of what your Lambda Function does.stringno
<a name="input_environment"></a> environmentA map that defines environment variables for the Lambda function.<pre>object({<br> variables = map(string)<br> })</pre>no
<a name="input_exclude_files"></a> exclude_filesA list of directories or folders to ignore, e.g.<br>exclude_files = ["test", "src/**/*.ts"]list(string)no
<a name="input_iam_role_name_prefix"></a> iam_role_name_prefixThe prefix string for the name of IAM role for the lambda function.stringno
<a name="input_kms_key_id"></a> kms_key_idThe ARN of the KMS Key to use when encrypting log data.stringno
<a name="input_lambda_kms_key_arn"></a> lambda_kms_key_arnThe ARN of the KMS Key to use when encrypting environment variables. Ignored unless environment is specified.stringno
<a name="input_layers"></a> layersList of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function.list(string)no
<a name="input_memory_size"></a> memory_sizeAmount of memory in MB your Lambda Function can use at runtime.numberno
<a name="input_permissions_boundary"></a> permissions_boundaryARN of the policy that is used to set the permissions boundary for the role.stringno
<a name="input_policy_arns"></a> policy_arnsA list of IAM policy ARNs attached to the lambda function.list(string)no
<a name="input_publish"></a> publishWhether to publish creation/change as new Lambda Function Version.boolno
<a name="input_reserved_concurrent_executions"></a> reserved_concurrent_executionsThe amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations.numberno
<a name="input_retention_in_days"></a> retention_in_daysSpecifies the number of days you want to retain log events in the specified log group.numberno
<a name="input_tags"></a> tagsA mapping of tags to assign to resources.map(string)no
<a name="input_timeout"></a> timeoutThe maximum number of seconds the lambda function to run until timeout.numberno
<a name="input_tracing_config"></a> tracing_configCan be either PassThrough or Active. If PassThrough, Lambda will only trace the request from an upstream service if it contains a tracing header with "sampled=1". If Active, Lambda will respect any tracing header it receives from an upstream service. If no tracing header is received, Lambda will call X-Ray for a tracing decision.<pre>object({<br> mode = string<br> })</pre>no
<a name="input_vpc_config"></a> vpc_configProvide this to allow your function to access your VPC.<pre>object({<br> security_group_ids = list(string)<br> subnet_ids = list(string)<br> })</pre>no

Outputs

NameDescription
<a name="output_iam_role"></a> iam_roleThe IAM Role which the lambda function is attached.
<a name="output_lambda_function"></a> lambda_functionThe lambda function.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->