aws-lambda: version incorrectly created when function property changes but value stays the same
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
This case is a bit convoluted but it happened to me multiple times, this is only my assumption of what's happening.
For a given function:
```
const fn = new NodejsFunction(this, "Func", {
environment: {
TEST: Fn.importValue("ValueFromOtherStack")
}
});
fn.addAlias("live");
```
When deployed a version will be correctly created, now assuming "ValueFromOtherStack" is exported as the string "test", if we change the deployment code to be:
```
const fn = new NodejsFunction(this, "Func", {
environment: {
TEST: "test"
}
});
fn.addAlias("live");
```
Without changing the function code, could be for the sake of changing the exported value (since you can't change export if they are already in use), the internal logic of Version will recalculate the logical id (this is my assumption) since the properties changed, yet when deploying to CF, CF will see the function's configuration to be the same and refuse to create a new version resulting in the following error:
```Version already exists: [...]. Please modify the function to create a new version.```
### Expected Behavior
Not sure, either creating a new version or not is fine by me but this fails deployment and happens quite frequently for me
### Current Behavior
Deployment fails and an artificial change has to be done to one of the function's properties.
If this was one function that would be one thing, but this happens for me on multiple occasions for multiple functions
### Reproduction Steps
Deploy function with the first code example
Attempt to deploy function with the second code example without changing any other property or function code and see the deployment fail
### Possible Solution
Not sure how can this be solved since CDK is right to assume the logical id changes here since the property changed, but it cannot see the values are the same due to them being deploy time variables
### Additional Information/Context
_No response_
### CDK CLI Version
2.102.0
### Framework Version
_No response_
### Node.js Version
any
### OS
any
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Reproduce the deployment with the two NodejsFunction examples, including addAlias("live"), using CDK CLI 2.102.0. Start by tracing how the Lambda Version logical ID responds to the environment property changing from Fn.importValue("ValueFromOtherStack") to "test". Done means the unchanged function no longer fails deployment with “Version already exists,” or the expected behavior and limitation are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100