aws / aws/aws-cdk

(lambda): add upsert alias

Open
#22,218 0 comments 3 reactions 1 assignee Claimed by @kaizencc View on GitHub
@aws-cdk/aws-lambda effort/medium feature-request p2
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.