-
Notifications
You must be signed in to change notification settings - Fork 4k
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 Code Hash changes after every git repository clone #8285
Comments
The code hash is computed based on the contents of the asset source -
If the asset source changes for any reason, a new hash will be computed (including hidden files). Can you check if the act of 'cloning' causing the asset source to change? If you're still seeing this, please provide more information around how you're defining lambda assets, the contents of the asset and what exactly you mean when you say 'clone the repo'. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
A simple repro : https://github.com/joraycorn/cdk-lambda-absolutepath
I would like to know if theres any work around for that case. Thanks ! |
I gave this a shot and cannot reproduce. The steps I took were -
Running a diff against |
I also get same behavior / asset hash With |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Oh no this should not have been closed. This IS an issue =( I will provide more information once I get back to work and have the time. |
Here is what I think is happening, if the lambda function code which is checked in is in |
@NetaNir That is a good hint, I thought of the same recently. I will update to the next typescript version, observe what happens and report back. I think this could explain why it is difficult to share a CDK repository with the team. If they a) use the globally installed TypeScript binary or b) the package.json contains a TypeScript version which is not fixed (e.g. using the npm caret), the hash changes with each individual that issues a deploy. |
@MartinLoeper - if this is the case, then the CDK is behaving as designed. Different versions of typescript can produce slightly different variations of the output javascript which can cause the asset hash to be produced differently. If the javascript handler for lambda function changes, I believe it is correct to deploy these into the lambda functions. Was/Is there an impact when assets changes (due to different typescript versions)? If not, I would leave it as is. However, if this is not desirable, you could compute your own source hash and pass it to the asset API. |
Yes @nija-at you are correct that this would be expected behaviour of the cdk in the first place. However, people who are responsible for building functional repositories must somehow find a solution to handle this case. The issue is the following: If you have a cdk app with a lot of TypeScript lambda functions and another person checks it out and deploys it, a lot of assets are uploaded. This leads to the following two inconveniences: a) The deployment is slowed down. Solution: Shouldn't it be possible to create an attribute for the NodejsFunction construct [1] which instructs the asset's hash being computed based on the underlying sources only? This attribute could be totally optional and defaulted to false. What do you think? Does it make sense? Let me put it another way: Does it make sense not to care about the generated lambda handler, but to specify a list of files which are used instead for change detection (e.g. package.json and the dist/ folder)? [1] https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html |
The code that gets executed in the lambda function is actually the Javascript generated file and not the original typescript source. One reason, folks use range dependencies is so that they can receive future bug fixes without any additional effort. The better way to fix this would be for you to depend on a fixed version of typescript. This way there is no variation in the code generated. When you're ready to upgrade, you can do so in a controlled manner (with a single commit) knowing that assets are going to change across the board. |
I think you are right @nija-at. I will double check if the typescript range in the package.json is the cause of this whole inconvenience. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
I have had this issue as well, where 2 developers, all the same versions of TS, same node versions, the compiled output was actually the same, still on 2 different machines we were getting different hashes every single time. |
I had this issue when synthesising with the CDK CLI, but if I synthesise with the CDK C# SDK the hashes remain the same. Just to spell it out: using the CDK C# SDK solved the problem for me. Don't ask me why there's this difference, but maybe the information can help someone else. |
I'm getting this issue too. Makes it so |
❓ General Issue
The Question
I have an issue with our current CDK app.
Whenever a colleague clones the repo containing the CDK app and runs a
cdk diff
, all Lambda functions are rebuilt. Somehow, the hash which is calculated for every Lambda function in the CDK app changes.This issue confuses our staff since they do not expect anything to change at all when they are not explicitly editing the Lambda functions.
Is it possible to make the hash computation more deterministic?
Actually, I do not know why the hash is changing for every full rebuild of the CDK app (i.e. removing all node_modules, cdk.out and bin directories).
However, I guess a solution would be to derive the Lambda's code hash from the version attribute in each Lambda's package.json file. Is this currently possible in the CDK?
Environment
Other information
Example diff after the repository with the CDK app was checked out:
The text was updated successfully, but these errors were encountered: