Skip to content

Latest commit

 

History

History
143 lines (106 loc) · 11.7 KB

File metadata and controls

143 lines (106 loc) · 11.7 KB

Fixit Cloud ☁️ Module: AWS Lambda

Terraform module for defining and managing an AWS Lambda function.

Table of Contents

Useful Links


⚙️ Module Usage

Usage Examples

Requirements

Name Version
terraform 1.3.2
aws ~> 4.34.0

Providers

Name Version
aws ~> 4.34.0

Modules

No modules.

Resources

Name Type
aws_iam_policy.Lambda_ExecRole_Policies_Map resource
aws_iam_role.Lambda_ExecRole resource
aws_iam_role_policy_attachment.Lambda_ExecRole resource
aws_lambda_event_source_mapping.list resource
aws_lambda_function.this resource
aws_lambda_permission.map resource
aws_lambda_provisioned_concurrency_config.this resource
aws_iam_policy_document.Lambda_ExecRole_Policies_Map data source

Inputs

Name Description Type Default Required
dead_letter_target_arn (Optional) ARN of SNS Topic or SQS Queue to notify when a function invocation
fails. If this option is used, the function's IAM role must be granted suitable
access to write to the target object, which means allowing either the sns:Publish
or sqs:SendMessage action on this ARN, depending on which service is targeted.
string null no
deployment_package_src The Lambda deployment package source; must be either an absolute path
to an executable on the local filesystem, an image URI, or an object
configuring retrieval from an S3 bucket.
object({
local_file_abs_path = optional(string)
image_uri = optional(string)
s3_bucket = optional(object({
bucket_name = string
object_key = string
object_version = string
}))
})
n/a yes
description (Optional) The Lambda function description. string null no
environment_variables (Optional) Map of env vars to make accessible to the function during execution. map(string) null no
event_source_mapping (Optional) Config object to setup an event source mapping for the Lambda function.
This allows Lambda functions to get events from Kinesis, DynamoDB, SQS, Amazon MQ
and Managed Streaming for Apache Kafka (MSK). Reference documentation for these
arguments is available here.
object({
enabled = optional(bool)
event_source_arn = optional(string)
filter_patterns = optional(list(string))
starting_position = optional(string)
starting_position_timestamp = optional(string) # RFC3339 timestamp
queues = optional(string)
batch_size = optional(number)
maximum_batching_window_in_seconds = optional(number)
maximum_record_age_in_seconds = optional(number)
maximum_retry_attempts = optional(number)
destination_config = optional(object({
on_success_dest_resource_arn = string # TODO this is not being used
on_failure_dest_resource_arn = optional(string)
}))
})
null no
execution_role Config object for the Lambda function's execution role.
object({
name = string
description = optional(string)
path = optional(string)
tags = optional(map(string))
add_edge_service_principal = optional(bool, false)
attach_policy_arns = optional(list(string))
attach_policies = optional(map(
# map keys: IAM policy names/IDs
object({
policy_json = optional(string)
statements = optional(list(object({
sid = optional(string)
effect = string
actions = list(string)
resources = optional(list(string))
conditions = optional(map(
# map keys: IAM condition operators (e.g., "StringEquals", "ArnLike")
object({
key = string
values = list(string)
})
))
})))
description = optional(string)
path = optional(string)
tags = optional(map(string))
})
))
})
n/a yes
handler (Optional) The Lambda function handler. string "index.handler" no
lambda_permissions (Optional) Map of principal names to Lambda permission config objects. Gives an
external source (like an EventBridge Rule, SNS, or S3) permission to access the
Lambda function. The principals can be AWS services, like "events.amazonaws.com",
or AWS account IDs - any external principal that requires permission to invoke
the Lambda function. With "qualifier" you can optionally narrow the permission to
just a specific version or function alias. To ensure the permissions granted are
not too broad, AWS service principals must be provided with a "source_arn"; for
example, if the principal is EventBridge (events.amazonaws.com), the "source_arn"
would be that of the EventBridge Rule. "principal_org_id" can be used to provide
permissions to all accounts within an Organization.
map(
# map keys: principal names ("events.amazonaws.com", account IDs, etc.)
object({
action = string # e.g., "lambda:InvokeFunction"
statement_id = optional(string)
qualifier = optional(string) # option to specify a version or alias
source_account = optional(string)
source_arn = optional(string) # Required if principal is an AWS service
principal_org_id = optional(string) # Principal would be the Org root account
})
)
{} no
name The Lambda function name. string n/a yes
provisioned_concurrent_executions (Optional) Amount of capacity to allocate. Must be greater than or equal to 1 (default 1). number 1 no
runtime (Optional) The Lambda function runtime; see link below for valid runtime values.
https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime
string null no
should_publish_new_version (Optional) Whether changes implemented by the module call should result
in a new version of the Lambda function; this is applicable to changes
made to existing Lambda functions as well as the creation of new ones.
bool true no
tags (Optional) The Lambda function tags. map(string) null no
vpc_config (Optional) VPC configs for the Lambda function.
object({
security_group_ids = list(string)
subnet_ids = list(string)
})
null no

Outputs

Name Description
Lambda_Event_Source_Mappings Map of Lambda event source mapping resource objects.
Lambda_Function The Lambda function resource object.
Lambda_Function_ExecutionRole The Lambda function execution role resource object.
Lambda_Function_Permissions Map of Lambda function permission resource objects.
Lambda_Function_Provisioned_Concurrency_Config The Lambda function provisoined concurrency config resource object.

📝 License

All scripts and source code contained herein are for commercial use only by Nerdware, LLC.

See LICENSE for more information.

💬 Contact

Trevor Anderson - @TeeRevTweets - Trevor@Nerdware.cloud

     

Dare Mighty Things.