Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda datasource that returns multiple functions and allows filters #17701

Closed
srkiNZ84 opened this issue Feb 19, 2021 · 3 comments · Fixed by #28254
Closed

Lambda datasource that returns multiple functions and allows filters #17701

srkiNZ84 opened this issue Feb 19, 2021 · 3 comments · Fixed by #28254
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-data-source Introduces a new data source. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@srkiNZ84
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

At the moment, for AWS Lambda, there only appears to be a "aws_lambda_function" datasource that returns a single function and that you have to know the name of the function for:

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function

This issue is a proposal is for a new "aws_lambda_functions" datasource that returns zero or more lambda functions based on a filter, like the "aws_instances" datasource (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/instances) but for Lambda functions.

Why?

I would like to use this datasource to feed it into a CloudWatch alarms resources and create an "alarm per function" to make it simpler to diagnose issues (in the current state, we have alarms which trigger if any lambda throws an error, which leaves the task of figuring out which Lambda it was to the unfortunate operator).

There are possible other use cases, basically any situation where you need a list of Lambda functions to create a "per function" resource as an example

New or Affected Resource(s)

  • aws_lambda_functions (new datasource)

Potential Terraform Configuration

data "aws_lambda_functions" "test" {
  lambda_tags = {
    Environment = "Test"
  }

  filter {
    name   = "lambda.runtime"
    values = ["Python 3.7"]
  }
}

resource "aws_cloudwatch_metric_alarm" "lambda_error_alarm" {
  count                     = length(data.aws_lambda_functions.test.ids)
  alarm_name                = "${data.aws_lambda_functions.test.name[count.index]}-lambda-error"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "2"
  threshold                 = "5"
  period                    = "60"
  alarm_description         = "Alarm triggers when the number of Lambda invocation errors goes above 5 in a one minute period for two consecutive minutes"
  alarm_actions             = [aws_sns_topic.system_alarms.arn]
  metric_name               = "Errors"
  namespace                 = "AWS/Lambda"
  dimensions = {
        FunctionName = data.aws_lambda_functions.test.name[count.index]
  }
  statistic                 = "Sum"
  insufficient_data_actions = []
}

References

N/A

@srkiNZ84 srkiNZ84 added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 19, 2021
@ghost ghost added service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/lambda Issues and PRs that pertain to the lambda service. labels Feb 19, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 19, 2021
@DrFaust92 DrFaust92 added the new-data-source Introduces a new data source. label Feb 19, 2021
@DrFaust92
Copy link
Collaborator

While there is a "ListFunctions" operations thats supported by the SDK, there isnt a way to filter by tags.
Adding the custom logic to filter after fetching is usually a maintenance burden as the api may expose this functionality later and break the provider's behaviour.

i believe maintainers wouldn't be for adding this custom logic if a data source for multiple lambda functions is added but ill leave the final say to them. just giving my two cents here.

A possible better solution that doesnt require custom logic is to implement the tagging group data source (corresponding to this https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html) that allows a generic solution for fetching resource by tag instead of service specific datasource.

@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 8, 2021
@github-actions github-actions bot added this to the v4.47.0 milestone Dec 13, 2022
@github-actions
Copy link

This functionality has been released in v4.47.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. new-data-source Introduces a new data source. service/cloudwatch Issues and PRs that pertain to the cloudwatch service. service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants