-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Feature request / bug: Improve checks for file updates #4897
Comments
Noted in the referenced issue, but I want to make sure this isn't missed: updating the lambda's code does not require a destroy of the resource. AWS creates additional aliases in this case. However, I personally find it annoying in situations where you're not interested in keeping old versions - it would be nice to be able to control the behavior from terraform (i.e.: provide a "create_alias" bool kind of option). |
Hi, It will be possible to trigger an update of a Lambda function by specifying an optional attribute resource "aws_lambda_function" "test_lambda" {
filename = "lambda_function_payload.zip"
function_name = "lambda_function_name"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "exports.test"
source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
} The update mechanism is also documented and docs update will be released along with the next version which makes it possible to update Lambda function. @muikrad I'm not entirely sure you can keep old versions of Lambda functions, although I know there's the concept of aliases that can be effectively used for versioning. In regards to keeping old versions of code I'd suggest deploying from versioned S3 bucket. If you have more specific suggestions on how Terraform could work with aliases for versioning feel free to describe that in a separate issue. |
@radeksimko to update a lambda function and use aliases, you must use the "update code" API call instead of deleting the lambda and recreating it again. There is no reason to delete a lambda version - this might actually create an unnecessary downtime! The AWS API has all these features, I don't understand why Terraform would do it another way if it can avoid deleting it. |
@muikrad if you have had a look at the linked PR, you would see that it is doing exactly what you described - using However my note was regarding Lambda aliases which can be used as an extra versioning layer within Lambda. If you have suggestions for solutions regarding that, please open a new issue with those suggestions. Thanks. |
Oh, awesome, then you are already creating versions. Sorry for not checking the PR. I guess the resource needs to output the version number of the updated code (probably from the update code response) into an output attribute. That way one could use it as an interpolation in other resources. I don't personally have a use case for this, but I guess having it handy would at least be a good start. |
@muikrad not exactly. The updates (as implemented in the linked PR) are currently performed in a way that a Lambda function is updated in-place (that's all the
We do not expose the Lambda version (yet), but it's basically always |
I'm sorry @radeksimko, but you are wrong. The version returned by the $LATEST is only a builtin alias to simplify accessing the most recent version; it is not a version per se and should only be used by calling entities if they don't care about which version they're calling. You can indeed use the So here's the catch: when you use the Here's a sample response for the
As you see, the |
@muikrad I'm not sure how you created/updated that function ^ but I'm pretty sure it wasn't via the latest version of Terraform in Admittedly I wasn't entirely right (u could say I was wrong 😉 ) about aws --region=us-west-2 lambda get-function --function-name=lambda_function_name {
"Code": {
"RepositoryType": "S3",
"Location": "https://***-us-west-2-tasks.s3-us-west-2.amazonaws.com/snapshots/*REDACTED*"
},
"Configuration": {
"Version": "$LATEST",
"CodeSha256": "60hXsKdYkfeql*REDACTED*mZDbGIrPnUHc=",
"FunctionName": "lambda_function_name",
"MemorySize": 128,
"CodeSize": 339,
"FunctionArn": "arn:aws:lambda:us-west-2:***:function:lambda_function_name",
"Handler": "exports.test",
"Role": "arn:aws:iam::***:role/iam_for_lambda",
"Timeout": 3,
"LastModified": "2016-03-14T13:42:07.081+0000",
"Runtime": "nodejs",
"Description": ""
}
} when I manually add |
Oh my, I apologize; I completely overlooked the Publish parameter. It was indeed set to True, which explains the results I'm having. I feel embarrassed now. Sorry to have taken so much of your time. |
No need to be embarrassed or apologise! I think it was worth discussing, so that anyone else searching for the same feature will find a thorough explanation here. 😉 |
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. |
It would be helpful if when given a file as a resource (such as in aws_lambda_function) that it actually checks the contents of the file. Currently, the resource update is only triggered if the location of file changes.
For example I have:
This runs fine, and works as expected, however, there are two issues I have with the current implementation.
It would be useful to be able to (either by default or via some option) to determine if the payload is actually different (e.g. checksum), instead of using the path.
The text was updated successfully, but these errors were encountered: