terraform-aws-modules / terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws
Apache License 2.0
909 stars 681 forks source link

Allow qualified arns for event source mapping for snapstart and provisioned concurrency #501

Closed FarhanSajid1 closed 10 months ago

FarhanSajid1 commented 12 months ago

Description

For some lambda functions there is a use case for using a feature called snapstart or provisioned concurrency both have the following requirement

You can use SnapStart only on [published function versions](https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html#configuration-versions-config) and [aliases](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html) that point to versions. You can't use SnapStart on a function's unpublished version ($LATEST).

You cannot use provisioned concurrency with the $LATEST version of any function.

In addition, if you're using an event source with your Lambda function, make sure that event source points to the correct alias or version. Otherwise, your function won't use provisioned concurrency environments.

A common setup is to have Lambdas be triggered from event sources like SQS, S3, Firehose, etc. The current code has the following logic

resource "aws_lambda_event_source_mapping" "this" {
  for_each = { for k, v in var.event_source_mapping : k => v if local.create && var.create_function && !var.create_layer && var.create_unqualified_alias_allowed_triggers }

  function_name = aws_lambda_function.this[0].arn

The function_name will always use the unqualified arn, which is essentially using $LATEST. And as such, snapstart and provisioned concurrency will never be enabled.

We can add a backwards compatible flag for event sources that will specify if the qualified version is required for the integration

resource "aws_lambda_event_source_mapping" "this" {
  for_each = { for k, v in var.event_source_mapping : k => v if local.create && var.create_function && !var.create_layer && var.create_unqualified_alias_allowed_triggers }

  function_name = try(each.value.require_qualified_name, false) ? aws_lambda_function.this[0].qualified_arn : aws_lambda_function.this[0].arn

If your request is for a new feature, please use the Feature request template.

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 10 months ago

This issue was automatically closed because of stale in 10 days

github-actions[bot] commented 9 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.