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

aws_lambda_alias not updating on new aws_lambda_function version #13099

Closed
niklaskhf opened this issue Apr 30, 2020 · 6 comments · Fixed by #14578
Closed

aws_lambda_alias not updating on new aws_lambda_function version #13099

niklaskhf opened this issue Apr 30, 2020 · 6 comments · Fixed by #14578
Labels
service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@niklaskhf
Copy link

niklaskhf commented Apr 30, 2020

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

Terraform Version

Terraform: v0.12.24
provider.aws: v2.59.0

Affected Resource(s)

  • aws_lambda_function
  • aws_lambda_alias

Terraform Configuration Files

resource "aws_lambda_function" "example" {
  function_name = "example-lambda"
  handler = "main"
  role = aws_iam_role.lambda_role.arn
  runtime = "go1.x"
  filename = "../code.zip"
  timeout = 20
  memory_size = 128
  reserved_concurrent_executions = 1
  publish = true
}

resource "aws_lambda_alias" "example" {
  name             = "example-alias"
  description      = "latest version"
  function_name    = aws_lambda_function.example.arn
  function_version = aws_lambda_function.example.version

  depends_on=[aws_lambda_function.example]
}

Debug Output

Panic Output

Expected Behavior

The aws_lambda_funcion resource gets updated to a new version, because publish=true. The aws_lambda_alias resource gets updated to the new version of aws_lambda_function.

Actual Behavior

The aws_lambda_funcion resource gets updated to a new version, because publish=true. The aws_lambda_alias does not get updated until the next apply.

Steps to Reproduce

  1. terraform apply -> aws_lambda_function gets updated
  2. terraform apply -> aws_lambda_alias gets updated

Important Factoids

References

@ghost ghost added the service/lambda Issues and PRs that pertain to the lambda service. label Apr 30, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 30, 2020
@yaochaoutokyo
Copy link

Exactly the same problem here. I tried to use a lambda alias named "prod" to point to the latest published version. However, when I modify the lambda function configuration and set the publish=true, the function gets a new version, but the alias doesn't get updated to the new version.

@jbilliau5668
Copy link

Yup, same here!

@andrewwheal
Copy link

This seems to be a regression of #2915

@kevinmstephens
Copy link

kevinmstephens commented Jul 17, 2020

I think I may have found the reason. I opened this ticket with my best guess at the cause. #14210.

Copied here:

Guess at Cause

I believe I have found the cause but I'd hope someone can confirm.

It seems that the auto-publish feature is used in updating lambdas. This API call to AWS will return the updated version. However the AWS provider doesn't appear to use that version and instead appears to call get-function-versions and grab the largest version from the return list and use that value. However, I've confirmed with AWS Support that get-function-versions isn't a strongly consistent call and in fact is eventually consistent and has a cache TTL (length unknown).

I believe that the calls to get-function-versions sometimes returns stale data and so the new version is not present.

To solve this issue the AWS provider should use the version returned from the update-function call (create-function call too if that's relevant).

@ghost
Copy link

ghost commented Feb 19, 2021

This has been released in version 3.29.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 for triage. Thanks!

@ghost
Copy link

ghost commented Mar 21, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 21, 2021
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants