Modernisation Platform Lambda Function Terraform Module

July 14, 2025 ยท View on GitHub

Standards Icon Format Code Icon Scorecards IconSCA Icon Terraform SCA Icon

Usage


module "lambda" {
  source                         = "github.com/ministryofjustice/modernisation-platform-terraform-lambda-function"
  application_name               = local.application_name
  tags                           = local.tags
  description                    = "lambda description"
  role_name                      = local.lambda_role_name
  policy_json                    = data.aws_iam_policy_document.lambda_policy.json
  function_name                  = local.lambda_function_name
  create_role                    = true
  reserved_concurrent_executions = 1
  environment_variables = {
    "key1" = "value1"
  }
  image_uri    = local.ecr_image_uri
  timeout      = 600
  tracing_mode = "Active"

  allowed_triggers = {
    AllowStopExecutionFromCloudWatch = {
      principal  = "events.amazonaws.com"
      source_arn = aws_cloudwatch_event_rule.lambda_cloudwatch_schedule_morning.arn
    }
    AllowStartExecutionFromCloudWatch = {
      principal  = "events.amazonaws.com"
      source_arn = aws_cloudwatch_event_rule.lambda_cloudwatch_schedule_evening.arn
    }
  }

}

Looking for issues?

If you're looking to raise an issue with this module, please create a new issue in the Modernisation Platform repository.

Requirements

NameVersion
terraform~> 1.0
aws~> 6.0

Providers

NameVersion
aws~> 6.0

Modules

No modules.

Resources

NameType
aws_iam_policy.policy_from_jsonresource
aws_iam_role.thisresource
aws_iam_role_policy_attachment.policy_arnsresource
aws_iam_role_policy_attachment.policy_from_jsonresource
aws_lambda_function.thisresource
aws_lambda_function_event_invoke_config.thisresource
aws_lambda_permission.allowed_triggersresource
aws_iam_policy_document.assume_roledata source
aws_iam_policy_document.combined-assume-role-policydata source

Inputs

NameDescriptionTypeDefaultRequired
additional_trust_rolesARN of other roles to be passed as principals for sts:AssumeRolelist(string)[]no
additional_trust_statementsJson attributes of additional iam policy documents to add to the trust policylist(string)[]no
allowed_triggersMap of allowed triggers to create Lambda permissionsmap(any){}no
application_nameName of applicationstringn/ayes
create_roleControls whether IAM role for Lambda Function should be createdbooltrueno
descriptionDescription of your Lambda Function (or Layer)string""no
environment_variablesA map that defines environment variables for the Lambda Function.map(string){}no
filenameThe absolute path to an existing zip-file to usestringnullno
function_nameA unique name for your Lambda Functionstring""no
handlerLambda Function entrypoint in your codestringnullno
image_uriThe ECR image URI containing the function's deployment package.stringnullno
lambda_roleIAM role ARN attached to the Lambda Function. This governs both who / what can invoke your Lambda Function, as well as what resources our Lambda Function has access to. See Lambda Permission Model for more details.string""no
memory_sizeAmount of memory in MB your Lambda Function can use at runtimenumber128no
package_typeThe Lambda deployment package type. Valid options: Image or Zipstring"Image"no
policy_arnsList of policy statements ARN to attach to Lambda Function rolelist(string)[]no
policy_jsonAn policy document as JSON to attach to the Lambda Function rolestringnullno
policy_json_attachedA json policy document is being passed into the moduleboolfalseno
policy_nameIAM policy name. It override the default value, which is the same as role_namestringnullno
reserved_concurrent_executionsThe amount of reserved concurrent executions for this Lambda Function. A value of 0 disables Lambda Function from being triggered and -1 removes any concurrency limitations. Defaults to Unreserved Concurrency Limits -1.number-1no
role_descriptionDescription of IAM role to use for Lambda Functionstringnullno
role_nameName of IAM role to use for Lambda Functionstringnullno
runtimeLambda function runtimestringnullno
sns_topic_on_failureSNS topic arn for the lambda's destination on failure.string""no
sns_topic_on_successSNS topic arn for the lambda's destination on success.string""no
source_code_hashHash value of the archive file. Calculated externally. Use to trigger updates when source file is changed.stringnullno
tagsCommon tags to be used by all resourcesmap(string)n/ayes
timeoutThe amount of time your Lambda Function has to run in seconds.number3no
tracing_modeTracing mode of the Lambda Function. Valid value can be either PassThrough or Active.stringnullno
vpc_security_group_idsList of security group ids when Lambda Function should run in the VPC.list(string)nullno
vpc_subnet_idsList of subnet ids when Lambda Function should run in the VPC. Usually private or intra subnets.list(string)nullno

Outputs

NameDescription
lambda_function_arnThe ARN of the Lambda Function
lambda_function_invoke_arnThe invoke ARN of the Lambda Function
lambda_function_nameThe Name of the Lambda Function
vpc_security_group_idsThe VPC security groups the lambda function has been deployed into
vpc_subnet_idsThe vpc subnet(s) the Lambda function has been deployed into