aws / aws/aws-cdk

aws-lambda: AWS::ApplicationAutoScaling::ScalableTarget does not clean up

Open
#31,507 5 comments 1 reaction 0 assignees View on GitHub
@aws-cdk/aws-lambda bug effort/medium needs-cfn p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When autoscaling is removed from a function alias, the provisioned concurrency configuration is not cleaned up by AWS::ApplicationAutoScaling::ScalableTarget

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

The provisioned concurrency should be deleted from the alias

### Current Behavior

It stays

### Reproduction Steps

- deploy the stack (see code below)
- see that the lambda alias has a provisioned concurrency of 1
- comment out line 17-20
- redeploy the stack
- see that the lambda still has the provisioned concurrency (it should be gone)

- now delete the stack
- deploy again (as a new stack, with the commented out code)
- see that there is no provisioned concurrency on the alias. (as expected)

in both flows, the final CF template is the same, but the resulting resource state is different, which is I assume not expected.

Stack code:
```typescript
import { Stack } from 'aws-cdk-lib';
import type { Construct } from 'constructs';
import { Alias, Function as LambdaFunction, InlineCode, Runtime } from 'aws-cdk-lib/aws-lambda';
export class ServiceStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const lambda = new LambdaFunction(this, 'function', {
code: new InlineCode('exports.handler = async (event) => console.log(event)'),
runtime: Runtime.NODEJS_18_X,
handler: 'index.handler',
});
const alias = new Alias(this, 'alias', {
aliasName: 'live',
version: lambda.currentVersion,
});

const autoScaling = alias.addAutoScaling({
maxCapacity: 5,
});
autoScaling.scaleOnUtilization({ utilizationTarget: 0.5 });
}
}
```

### Possible Solution

AWS::ApplicationAutoScaling::ScalableTarget should clean up the provisioned concurrency configuration when being removed from the stack

### Additional Information/Context

_No response_

### CDK CLI Version

2.149.0

### Framework Version

_No response_

### Node.js Version

v16.20.2

### OS

5.10.224-190.876.amzn2int.x86_64

### Language

TypeScript

### Language Version

5.0.4

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the Alias.addAutoScaling entry point and trace how it produces AWS::ApplicationAutoScaling::ScalableTarget. Reproduce the two deployment flows from the issue, then verify that removing autoscaling deletes the alias's provisioned concurrency and leaves the redeployed state consistent with a fresh stack.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.