aws / aws/aws-cdk-cli

(cli): Hotswap causes `InvalidParameterValueException` on Lambda Aliases

Open
#628 0 comments 0 reactions 0 assignees View on GitHub
bug effort/medium p2
Dominant language
TypeScript
Stars
105
Forks
122
Avg merge
2d 2h
Merged PRs (30d)
69

Description

### Describe the bug

The second time you hot-swap a Lambda with an Alias in CDK watch mode, the hot-swap causes an `InvalidParameterValueException`.

![image](https://user-images.githubusercontent.com/644092/194613777-75237929-588c-4436-94f7-46f4abc315e7.png)

### Expected Behavior

The hot-swap should succeed.

### Current Behavior

The CDK CLI errors with `InvalidParameterValueException`.

### Reproduction Steps

I have pushed up a repository that can reproduce the issue here: https://github.com/misterjoshua/cdk-alias-hotswap-bug/blob/main/src/main.ts

**To reproduce:**
- Checkout the repo
- `yarn install`
- `yarn watch` (this does `cdk watch` in this projen project)
- Let it deploy the first time
- Change the lambda handler code - it may succeed to hot-swap the first time
- Change the lambda handler code a second time
- You should see the error at this point.

Here's another copy of the code for reference:

```ts
import { App, aws_apigateway, aws_lambda, Stack } from 'aws-cdk-lib';

const app = new App();

const stack = new Stack(app, 'cdk-alias-hotswap-bug', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
},
});

const handler = new aws_lambda.Function(stack, 'Handler', {
code: aws_lambda.Code.fromInline([
'def handler(event, ctx):',
' return { "statusCode": 200, "body": "{}" }',
// Introduce randomness for convenience so you can hit save on this file
// to redeploy and trigger the bug.
` #${Math.random()}`,
'',
].join('\n')),
runtime: aws_lambda.Runtime.PYTHON_3_9,
handler: 'index.handler',
});

// Add provisioned concurrency
const handlerAlias = handler.addAlias('abcd', {
provisionedConcurrentExecutions: 3,
});

// Use the provisioned concurrency as the rest api handler
new aws_apigateway.LambdaRestApi(stack, 'Api', {
handler: handlerAlias,
});

app.synth();
```

### Possible Solution

I'm unsure what the solution would be.

### Additional Information/Context

_No response_

### CDK CLI Version

2.45.0

### Framework Version

TypeScript

### Node.js Version

14.19.1

### OS

Linux

### Language

Typescript

### Language Version

TypeScript (4.8.4)

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by running the reproduction from src/main.ts with yarn install and yarn watch, then trigger two Lambda handler changes as described. Trace the CDK watch hotswap path for the Lambda alias with provisioned concurrency. Done means repeated hotswaps succeed without InvalidParameterValueException.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.