aws_lambda: regular deploys fail after hotswap
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
After deploying a lambda version with `--hotswap`, when you attempt to run a regular `cdk deploy` with the same changes it fails with the following error message:
```
Resource handler returned message: "Version already exists: [arn:aws:lambda:ap-southeast-2:572093383043:function:serviceName:96]. Please modify the function to create a new version. (Service: Lambda, Status Code: 409, Request ID: aa44dd2b-8347-4e8a-996e-408a52e648ec)" (RequestToken: 0af5f624-50e3-8943-96d4-16687d2fe1fb, HandlerErrorCode: AlreadyExists)
```
### Expected Behavior
Regular `cdk deploy` succeeds after a hotswap deploy
### Current Behavior
`cdk deploy` fails.
### Reproduction Steps
https://github.com/samchungy/cdk-lambda-hotswap-bug
run `ENVIRONMENT=dev yarn deploy`
```
const worker = new aws_lambda_nodejs.NodejsFunction(this, 'worker', {
architecture: aws_lambda.Architecture.ARM_64,
runtime: aws_lambda.Runtime.NODEJS_20_X,
entry: './src/app.ts',
timeout: Duration.seconds(30),
bundling: defaultWorkerBundlingConfig,
functionName: 'serviceName',
environment: {
...defaultWorkerEnvironment,
...context.workerLambda.environment,
},
});
```
Run `--hotswap` followed by deploy without
### Possible Solution
I assume this is failing because the function configuration hasn't changed between a hotswap deploy and a regular deploy. So when CF goes to sync up and the version configuration is the same it fails
My workaround at the moment is adding a dynamic description which means that the Lambda has to be deployed fresh with every deploy.
This may just have to be an accepted quirk, but perhaps some documentation around this would be great
### Additional Information/Context
_No response_
### CDK CLI Version
2.110.0
### Framework Version
_No response_
### Node.js Version
20
### OS
Mac OSX
### Language
TypeScript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Reproduce the failure in the linked cdk-lambda-hotswap-bug repository by running `ENVIRONMENT=dev yarn deploy`, then repeating the deployment with `--hotswap` followed by a regular `cdk deploy`. Start by tracing the CDK CLI hotswap path for the TypeScript `NodejsFunction`; done means a regular deploy succeeds afterward without requiring a dynamic description workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cli, cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100