-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Get latest version number of data source aws_lambda_function #10038
Comments
…for unpublished lambda)
This commit adds a Lambda alias called latest that points to the most recently published version of the function. This is a workaround for a defect in the data source aws_lambda_function: hashicorp/terraform-provider-aws#10038
This commit adds a Lambda alias called latest that points to the most recently published version of the function. This is a workaround for a defect in the data source aws_lambda_function: hashicorp/terraform-provider-aws#10038
This commit adds a Lambda alias called latest that points to the most recently published version of the function. This is a workaround for a defect in the data source aws_lambda_function: hashicorp/terraform-provider-aws#10038
This commit adds a Lambda alias called latest that points to the most recently published version of the function. This is a workaround for a defect in the data source aws_lambda_function: hashicorp/terraform-provider-aws#10038
@flo-sch Yes, setting an alias called latest in Terraform code works fine as a workaround for CloudFront. |
Has there been any progress on the data resource for this? I'm keen not to hardcode the version number if I can help it. |
I could really do with a fix for this issue too, although as I do publish the Lambda functions via another Terraform run, I am able to extract the latest version number that was deployed by Terraform using the following code (edited to remove some specifics).
I hope this helps someone until this fix gets landed. |
Thank you! It works fine for me... |
I arrived here by looking for how to set up this with a resource, not data.
That works like a charm. |
My workaround: One terraform:
Completely different terraform/different state in the same infra:
Works like a charm... |
I guess those workaround only work when publishing the lambda with Terraform though? I might have missed to mention that, but in my initial use-case, Lambda functions were published by something else (serverless framework), hence the proposal for a new |
The deployment method has nothing to do with it. You can even clickops it, then use terraform |
Oh nice, I missed that, then that sounds like a decent workaround indeed! |
This is perfect! Easiest solution to implement for this case! |
@tymik @Woitekku I tried the same steps, but the qualifier still points to one version older data "aws_lambda_alias" "current" { resource "aws_lambda_provisioned_concurrency_config" "lambda_warming" { --> the above code sets the provisioned concurrency on the previous version. (example: "alias: current" --> v5, concurrency set on v4) I also tried this and its same behavior, concurrency set on previous version. Any suggestions? |
@sriniavgs it seems that you are missing the You might also want to check AWS docs regarding Lambda versions and aliases |
To associate a lambda function to CloudFront distribution as a Lambda@Edge (using a cache behiavor's lambda_function_association block), it is required to provide a numbered version. The `qualified_arn`, unfortunately, always returns `$LATEST` which is not supported by Lambda@Edge. There appears to be no easy way to query `aws_lambda_function.version` either. See: hashicorp/terraform-provider-aws#10038 hashicorp/terraform-provider-aws#25448
Update: In my particular case, the versioned ARN is available as an output from the CloudFormation, so I'm set. I'm trying @Woitekku 's workaround. The function was generated by a CloudFront template (via Terraform), so I don't think I have any more direct access to it as a resource. data "aws_lambda_alias" "cognito_auth__check_auth_handler__localdev" {
provider = aws.us-east-1
function_name = "serverlessrepo-localdevCloudfront-CheckAuthHandler-yCGyEJodo4jh"
name = "latest"
}
data "aws_lambda_function" "cognito_auth__check_auth_handler__localdev" {
provider = aws.us-east-1
function_name = "serverlessrepo-localdevCloudfront-CheckAuthHandler-yCGyEJodo4jh"
qualifier = data.aws_lambda_alias.cognito_auth__check_auth_handler__localdev.function_version
} However, Terraform throws this, which I don't know how to interpret:
Do you know what this means and how to solve it? |
@jamiejackson you need to define an additional provider for here's a snippet:
|
This functionality has been released in v4.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. Thank you! |
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. |
Community Note
Description
To associate a lambda function to CloudFront distribution as a Lambda@Edge (using a cache behiavor's lambda_function_association block), it is required to provide a numbered version. The qualifier
$LATEST
will (unfortunately) not work.At the moment, that data source allow to pass a
qualifier
as an argument, but itsqualified_arn
attribute will reference that exact same qualifier, not necessarily a version number, unless the attribute itself is a version number, but that requires that version number to be known.From what I understand, the AWS SDK does not provide a built-in function to get the last published version directly, but as a workaround, it can be retrieved using the pagination API, such as shown in the resource aws_lambda_function:
https://github.com/terraform-providers/terraform-provider-aws/blob/v2.27.0/aws/resource_aws_lambda_function.go#L583
New or Affected Resource(s)
Proposal: add new attributes to the data source
aws_lambda_function
to access the latest numbered version (and/or even better: the fully qualified latest numbered version?)(better names can probably be found)
Potential Terraform Configuration
This is an example how what would be possible with such a feature:
References
If the change can be resumed to something as simple as copy-pasting the behavior of the resource to the data source, I would be more than happy to create a PR for it myself.
I would like to get some feedback on the proposal before starting, though.
And since I have never written a single line of Go code in my life before, I would need some guidance regarding contribution and especially testing, if that is possible?
The text was updated successfully, but these errors were encountered: