(lambda): add upsert alias
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
Create an alias with a name that you provide (unless an alias already exists), and points to the updated version of the Lambda function.
### Use Case
Currently I'm trying to achieve updating the alias of the lambda function on every deploy
```typescript
aliases.forEach(aliasName=>{
const alias = lambda.addAlias(aliasName);
alias.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
})
```
In this use case I'm basically tagging it with the git hash and the environment it's in.
The git hash is obviously unique but the environment alias for the environment I'm trying to "move" to the new version automatically.
This works until a new version of the function is detect and I get an error "alias already exists".
use flow
- deploy with alias: "production", "< gitHash >"
- deploy with alias: "preview", "< gitHash >"
- deploy with alias: "production", "< gitHash >" <--gets error here
### Proposed Solution
```typescript
lambda.addAlias(aliasName,{autoPublish:true});
```
it seems SAM already has a feature similar to what I'm looking for, is this achievable for cdk? [AutoPublishAlias](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/automating-updates-to-serverless-apps.html)
### Other Information
I tried looks through docs and code and couldn't seem to find a way to do this
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.43.0
### Environment details (OS name and version, etc.)
macOS Monterey
Contributor guide
Assessment
This issue has not been assessed yet.