Skip to content

harrison-ai/harrison-terraform-module-aws-lambda

Repository files navigation

A Terraform Module to deploy Image based AWS Lambda Functions.

This module attempts to understand its place in the universe and does not attempt to be all things to everyone. If that is what you want, this is what you are after.

This module is opinionated, yet flexible enough to be really useful. Here are some of the opinions it holds:

  • It only caters for container image based Lambda Functions
  • It assumes it will be triggered by an SQS queue
  • It does not support features that we don't envisage using, such as:
    • EFS
    • VPC
    • KMS Encryption of Environment Variables
    • Layers (by virtue of only supporting Container Image based funcctions)

Requirements

Name Version
terraform >= 1.5
aws >= 5.0

Providers

Name Version
aws >= 5.0

Modules

No modules.

Resources

Name Type
aws_cloudwatch_log_group.this resource
aws_iam_policy.this resource
aws_iam_role.this resource
aws_iam_role_policy_attachment.aws_managed_sqs_execution resource
aws_iam_role_policy_attachment.this resource
aws_lambda_event_source_mapping.this resource
aws_lambda_function.this resource
aws_sqs_queue.dlqueue resource
aws_sqs_queue.queue resource
aws_iam_policy_document.lambda_assume_role data source

Inputs

Name Description Type Default Required
architectures Architectures to use. For example x86_64. list(string) n/a yes
batch_size The largest number of records that Lambda will retrieve from the queue at the time of invocation. Defaults to 10 for SQS. number 10 no
cloudwatch_retention_in_days Days to keep Cloudwatch logs before they are deleted. number 30 no
command Command to run in Lambda. This is equivalent to Docker CMD. list(string) null no
description Description of the Lambda. string n/a yes
entry_point Entrypoint of Lambda. This is equivalent to Docker ENTRYPOINT. list(string) null no
envvars Map of environment variables for the Lambda function. map(string) {} no
ephemeral_storage_size Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). number 512 no
function_response_types Set to ReportBatchItemFailures to allow Lambda to return paritial success/failures. list(string) [] no
iam_abac_tags ABAC tags to pass. See https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html map(string) {} no
image_uri Private ECR repository URI. string n/a yes
lambda_policy Additional aws_iam_policy resource to include. string null no
maximum_batching_window_in_seconds The maximum amount of time to gather records before invoking the function, in seconds (between 0 and 300). Records will continue to accumulate until either maximum_batching_window_in_seconds expires or batch_size has been met. number 30 no
memory_size Memory size of the lambda in megabytes. string n/a yes
name Name of the Lambda. string n/a yes
sqs_encryption_enabled Boolean to enable server-side encryption (SSE) of message content with SQS-owned encryption keys. bool false no
sqs_max_message_size The limit of how many bytes a message can contain before Amazon SQS rejects it. An integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). The default for this attribute is 262144 (256 KiB) number 262144 no
sqs_max_receive_count The number of times a message is delivered to the source queue before being moved to the dead letter queue. number 10 no
sqs_message_retention_seconds The number of seconds Amazon SQS retains a message. Integer representing seconds, from 60 (1 minute) to 1209600 (14 days). number 1209600 no
sqs_queue_arn ARN of an existing SQS event source queue. string null no
sqs_queue_name Name of the event source queue if you want this module to create a combination queue and dead letter queue. string null no
sqs_receive_wait_time_seconds The time for which a ReceiveMessage call will wait for a message to arrive (long polling) before returning. An integer from 0 to 20 (seconds). number 20 no
sqs_visibility_timeout_seconds The visibility timeout for the queue. An integer from 0 to 43200 (12 hours). number 300 no
timeout Lambda timeout in seconds. string n/a yes
tracing_mode Whether to to sample and trace a subset of incoming requests with AWS X-Ray. Valid values are PassThrough and 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. string null no

Outputs

Name Description
dl_queue_arn Dead letter queue arn.
dl_queue_url Dead letter queue url.
lambda_function_arn Lambda function arn.
queue_arn Queue arn.
queue_url Queue url.

About harrison.ai

This module is maintained by the Platform team at harrison.ai.

At harrison.ai our mission is to create AI-as-a-medical-device solutions through ventures and ultimately improve the standard of healthcare for 1 million lives every day.

License

Licensed under the Apache License, Version 2.0.

Copyright 2022 harrison.ai Pty. Ltd.