-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Deploying new version of lambda function #5334
Comments
Hello @duarten , the error you're getting:
I assume is coming up during deployment, in CloudFormation? Thanks, |
Hi @skinny85, Yes, that's correct. |
Right. So the way we usually deal with that in the CDK is to have a new version for every synthesis - this way, the new version will always be created. Take a look at this example in our docs. |
Correct me if I'm wrong, but in that case won't a synthesis always change from the previous one, even though the Lambda's code and configuration didn't? It also doesn't seem to solve my original problem, since I may deploy a stack which contains a lambda function whose code and configuration didn't change, but the CDK version did, thus leading to the |
Yes. It's a tradeoff: either you remember to change it, or you accept the fact that you'll get a new version every deployment. I don't think it's too big of an issue to be honest.
No. It doesn't matter that the code/configuration did not change, there will be a new version, so you won't get that error. |
Sorry, I don't follow. The issue is that I specified a new version, and I got that error. If I don't change the version, then the CloudFormation template is the same and CDK doesn't attempt a deployment. If I change the version, CDK will attempt a deployment, but will fail with that error. (I guess that's some other layer complaining that the Lambda's code and configuration have not changed.) Example:
Note that version is
|
Hmm, you are correct. Apologies. I wonder whether Lambda added this validation recently...? I swear this used to work. |
No worries :) |
So here's my research on the topic. Currently, we recommend customers to do the following: const version = func.addVersion(new Date().toISOString()); // <==
const alias = new lambda.Alias(this, 'LambdaAlias', {
aliasName: 'Prod',
version,
});
new codedeploy.LambdaDeploymentGroup(this, 'DeploymentGroup', {
alias,
deploymentConfig: codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE,
}); However, it seems that this no longer works - if the Lambda itself is unchanged from the previous version, the new This needs some pretty serious changes in our API:
|
Actually, I figured out a workaround :) changing the const func = new lambda.Function(this, 'lambdaName', {
// whatever properties you need...
description: `Generated on: ${new Date().toISOString()}`,
});
const version = func.addVersion(new Date().toISOString());
const alias = new lambda.Alias(this, 'lambdaName-alias', {
aliasName: 'live',
version: version,
});
new codedeploy.LambdaDeploymentGroup(this, 'lambdaName-deployment', {
alias: alias,
deploymentConfig: codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE,
}); |
Thanks for the workaround :) |
thanks for the working workaround ;) I'm facing the same issue and I tried many actions before. I think that a better way to solve this problem is to wait until the SAM CDK module is finally stable and released and then use the |
I'm glad it worked @cbertozzi :) But I think the |
+1 on |
Additionally, I would love a feature to set the version to be retained on update. Sometimes I want the new version to be deployed but old versions to be retained for callers outside of my Stack. (e.g. Alexa Skills) |
I'm just trying to get AWS Lambda provisioned concurrency and autoscaling working, and ran into this issue. I think this is ridiculous - I don't care about versions or aliases, but I have to use them to get provisioned concurrency, but versions and aliases are broken in the CDK. Great. I suggest you guys think of an easier way to "deploy a lambda with provisioned autoscaling" with CDK. The workaround of "random description for lambda fn" seems to work for me, but man are things slow. A single function alias update takes 2 1/2 minutes with provisioned concurrency: 2/5 | 10:54:05 PM | UPDATE_IN_PROGRESS | AWS::Lambda::Alias | webhook-alias (webhookalias09ADCD64) |
There's also the case of Lambda@Edge, which I think relates to this issue: CloudFront requires that a specific version of Lambda function is associated with the distribution. Currently my options are:
… or
I'd like to see exactly that kind of code hash based solution @skinny85 suggested in #5334 (comment) as it should resolve this challenge with Lambda@Edge. |
[From Lambda, just throwing opinion here] Ran a few experiments, and this is partially dangerous and can lead to weird edge cases, though I do agree with the opinion that we should do this. As an example, let's say you have the following environment variables in your function:
and you "update" to:
Lambda does not see this as an update to your function. It's an idempotent "update", because it's a map which has no explicit ordering. If you were to try to Cloudformation does not interact kindly when you go from 1 -> 1. It will fail updates with If we were to naively hash the text within the function, Cloudformation will fail this update if you move from Sorry that it's frustratingly hard to get this right. We (Lambda+Cfn) need to do a bit better with these interactions and I'll start opening up communications to see what we can do --but due to backwards compatibility constraints of the past 5 years since this was originally shipped, the ship of "changing this" may have sailed. |
Examples of what I'm talking about above here: https://github.com/iph/lambda-experiments/tree/master/versioning-updates-cfn Specifically experiment 3 in the README. |
It is common for AWS services to require an explicit AWS Lambda Version when referencing functions. When an `AWS::Lambda::Version` resource is defined in CloudFormation is captures the AWS Lambda configuration *at the time of the creation of the version resource. This means that if the function's configuration or code is updated, the Version resource will no longer point to the function defined in the stack. To address this, we introduce a property `function.currentVersion` which will create a new AWS::Lambda::Version resource every time the function's configuration changes. This is done by encoding a hash of the function's CloudFormation properties into the logical ID of the version resource. Additionally, this change adds `version.addAlias` which makes it easier to define an AWS Lambda alias for a version. The result is this: fn.currentVersion.addAlias('live'); We employ an approach similar to apigateway's "Deployment" resource in order to implement `currentVersion`: during "prepare", we synthesize the CloudFormation template snippet of the AWS::Lambda::Function resource, calculate an MD5 for it and append it to the logical ID of the version resource. Resolves #6750 Resolves #5334
Facing the same issue in combination with CDK pipelines. |
Facing the same issue with SAM... any ideas for workarounds? |
5-6 minutes for mine . Slower than a rolling deploy of a small ECS Fargate cluster : ( |
I am using a |
Is there any fix to this? Creating and deploying new versions on each cdk deploy is a massive waste of resource. |
@mikoz93 this should be fixed with hotswap deployments. |
When using hotswap deployments along with provisioned concurrency and aliases, I'm still seeing the same delay. The Alias continues to weight the old version at 100% and the new version at 0% for several minutes. I've also tried adding an AllAtOnce deployment group but that didn't work either. The deployment group appeared to have no effect on the Alias deployment and version cutover
When using hotswap without aliases, the hotswap switch is instantaneous. |
@ajhool I think that’s because you’re using a CodeDeploy deployment group. Try removing it, and the Alias should be updated immediately. |
I know this is closed, but it's hard to tell if this issue is really resolved or not. Is it still necessary to append a timestamp to the description? As far as I can tell, it is. But if not, in what version of the CDK is this issue fixed? |
@jtaub it should be resolved, unless you put the Alias inside a CodeDeploy DeploymentGroup. |
@skinny85 i am still facing same issue. until few days back its working fine, when we added lambda auto scaling to alias. it has started failing with same error. now my cdk stack few lambdas, how can we handle this? even there are no changes to other lambdas it shows i cant keep changing description for other lambdas or anything that try to deploy lambda every time. what is the solution to this? wondering its working till Nov, 15th. Is there any configuration that we need to set? |
Why? |
@skinny85 What I am trying to say is that previously, if there were no changes in a Lambda function with Alias, AWS CDK would skip deploying that Lambda. I have 20 stacks, each with dozens of Lambdas, and my pipeline runs on a daily schedule. This setup used to work fine—if there were no changes to a Lambda, CDK would skip it. However, now CDK seems to expect every Lambda with an alias to have changes and deploy a new version, even if there’s no actual change. I have read few suggestions in comments to this thread like updating the description on every deployment to force a change, but that’s not practical in my case. Doing so would significantly increase compute utilisation in my pipeline, pushing it to its limits. What changed recently to cause this behaviour, and how can I make my pipeline work as it did before? Is there a reliable solution to prevent unnecessary Lambda deployments while keeping the pipeline efficient? |
Can you explain this? What would increase here? This is just a CloudFormation deployment, no? |
@skinny85 Exactly! This is a CloudFormation deployment executed via AWS CodeCatalyst workflows (CI/CD pipeline). For example, if I have 10 Lambdas with no changes, CDK skipping those would make my CodeCatalyst workflow run faster, saving time. This is because the workflow waits for the current CloudFormation deployment to complete, and that waiting time counts toward the total execution time. However, if I force updates to every Lambda, it will unnecessarily increase the total execution time of the CodeCatalyst workflow. |
In that case, I think you're only option is top update the description of the changes Lambdas manually, unfortunately 😕. |
I am wondering—this was working as expected just a few days ago. Why isn’t it working now? Did something change? |
I have no idea. Did you update your CDK version? According to the comments on this issue, it never worked, so I have no idea how it worked for you without knowing details about your setup, and its history. |
@skinny85 looks the bug is introduced with new version of cdk. |
❓ General Issue
The Question
I'm attempting to setup a CodeDeploy deployment group for a Lambda function. The CDK documentation for the Version class states:
This suggests that if I want to make a new CodeDeploy deployment, I should change the version name. For this end, I'm naming the versions using the sha1 of the latest Git commit that affects the Lambda's code or configuration. However, if I commit code that makes cosmetic changes to the configuration (i.e., to CDK code pertaining to the lambda), that will produce no differences in the CloudFormation template, and I will get the error
A version for this Lambda function exists ( 1 ). Modify the function to create a new version
.This suggests that for a new version to be deployed I need to change the code or make semantic changes to the configuration. If this is the case, why require the version name to be unique between versions?
Code:
Environment
Other information
The text was updated successfully, but these errors were encountered: