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

execute aws_lambda_invocation only once #4746

Closed
DJAlPee opened this issue Jun 5, 2018 · 18 comments · Fixed by #19488
Closed

execute aws_lambda_invocation only once #4746

DJAlPee opened this issue Jun 5, 2018 · 18 comments · Fixed by #19488
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@DJAlPee
Copy link

DJAlPee commented Jun 5, 2018

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 "me too" comments, 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

After creating an aws_lambda_function I want directly to trigger it for a first initialization. Currently I'm doing this using a provisioner and and some shell commands, which are invoking the the lambda with the AWS CLI.

I've seen there is now an aws_lambda_invocation data source, which does exactly the same like my provisioner. In my case, the disadvantage of a data source is, that the lambda is executed every time I do
a "terraform plan" or "terraform apply", which is not needed and increases the execution time (and AWS costs).

It would be nice to be able to trigger a lambda function only once

New or Affected Resource(s)

Option 1
Create:

resource "aws_lambda_invocation" "invoke"

Option 2
Update:

data "aws_lambda_invocation" "invoke"

Potential Terraform Configuration

I would prefer the first option, to create a new ressource type. It would look like the data source:

resource "aws_lambda_invocation" "example" {
  function_name = "${aws_lambda_function.lambda_function_test.function_name}"

  input = <<JSON
  {
    "key1": "value1",
    "key2": "value2"
  }
  JSON
}

As an alternative an optional attribute in the data source can manage the behavior:

data "aws_lambda_invocation" "example" {
  function_name = "${aws_lambda_function.lambda_function_test.function_name}"
  trigger_once  = true

  input = <<JSON
  {
    "key1": "value1",
    "key2": "value2"
  }
  JSON
}

References

No references

@DJAlPee
Copy link
Author

DJAlPee commented Jun 11, 2018

One further idea on that:
An additional attribute in the resource like e.g. "hash" (stored only in the state) can be you used for forcing a "recreation" of the invocation resource, which will trigger the invocation call each time, a certain depending resource was changed

@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service. labels Jun 13, 2018
@kkapoor1987
Copy link

Is this becoming kinda issue for us. Is there a way to not run data during apply ?

@dedunumax
Copy link
Contributor

Can I work on this? I think first option should be the solution.

@dedunumax
Copy link
Contributor

Temporarily, I created this community provider. https://registry.terraform.io/providers/dedunumax/awslambda/latest But you might need Terraform 0.13 to try that.

@mcsloe
Copy link

mcsloe commented Oct 1, 2020

As a workaround, I did the following:

# run lambda during apply only
data aws_lambda_invocation run {
  function_name = "my-lambda"

  input = <<JSON
{
  "APPLY_DATE": "${formatdate("DD MMM YYYY hh:mm ZZZ", timestamp())}",
 ...
}
JSON
}

@Michenux
Copy link

Michenux commented Nov 9, 2020

Any news about this issue ?
What's the recommended way until it's fixed ?

@dedunumax
Copy link
Contributor

I have made a PR to fix this. But it is not merged yet.

@rmccarthy-ellevation
Copy link

Any update on if the PR is merged?

@geofflancaster
Copy link
Contributor

Bump. Can this get merged?

@pascal-cosmic-cloud
Copy link

Please upvote the new PR, thanks.

@vibou
Copy link

vibou commented Jul 4, 2021

Please merge this as it is a so important BC Break between 0.12 and 0.13 without any workaround besides this new resource.

@vibou
Copy link

vibou commented Jul 4, 2021

As a workaround, I did the following:

# run lambda during apply only
data aws_lambda_invocation run {
  function_name = "my-lambda"

  input = <<JSON
{
  "APPLY_DATE": "${formatdate("DD MMM YYYY hh:mm ZZZ", timestamp())}",
 ...
}
JSON
}

So in the lambda you actually check the event is not empty?

@breathingdust
Copy link
Member

Hi all 👋 Just letting you know that this is issue is featured on this quarters roadmap. If a PR exists to close the issue a maintainer will review and either make changes directly, or work with the original author to get the contribution merged. If you have written a PR to resolve the issue please ensure the "Allow edits from maintainers" box is checked. Thanks for your patience and we are looking forward to getting this merged soon!

@breathingdust breathingdust added this to the Roadmap milestone Nov 10, 2021
@JackPott
Copy link

JackPott commented Jan 4, 2022

When does the quarter finish?

@vibou
Copy link

vibou commented Jan 9, 2022

any heads up on this one?

@YakDriver YakDriver self-assigned this Jan 18, 2022
@github-actions github-actions bot modified the milestones: Roadmap, v3.73.0 Jan 20, 2022
@YakDriver
Copy link
Member

Thank you for your patience. This functionality has been merged and should be part of the next version.

@github-actions
Copy link

This functionality has been released in v3.73.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 May 18, 2022
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. service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet