aws-elasticloadbalancingv2-targets: LambdaTarget for external function throws error
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
When using the result of `Alias.fromAliasAttributes` as the argument of a `LambdaTarget`, it throws `ValidationError: Cannot modify permission to lambda function. Function is either imported or $LATEST version.` (whereas the similar `aws-apigateway` `LambdaIntegration` handles that input just fine). When using the (more verbose) `Function.fromFunctionAttributes` form (with `skipPermissions: true`), then the error thrown is `Error: [object Object] does not implement IDependable. Use "Dependable.implement()" to implement`, presumably because `grantInvoke` yields an undefined `policyDependable` with an external function/alias. https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-elasticloadbalancingv2-targets/lib/lambda-target.ts#L22
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
Allow having a `LambdaTarget` from outside the stack.
### Current Behavior
Boom
### Reproduction Steps
```
// const aliasReference = Alias.fromAliasAttributes(stack, "alias", { aliasName, aliasVersion }); // would be preferred, simpler
const aliasReference = Function.fromFunctionAttributes(stack, "alias", { functionArn, skipPermissions: true });
// throws:
const tg = new ApplicationTargetGroup(stack, "tg", { targetGroupName, targets: [new LambdaTarget(aliasReference)] });
```
### Possible Solution
Don't try to grant automatically
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
aws-cdk-lib@2.216.0
### AWS CDK CLI version
2.1029.2 (build fccc5f9)
### Node.js Version
v18.20.8
### OS
macOS 15.6.1
### Language
TypeScript
### Language Version
TypeScript (5.8.2)
### Other information
_No response_
Contributor guide
Research direction
Start in packages/aws-cdk-lib/aws-elasticloadbalancingv2-targets/lib/lambda-target.ts, then compare how the aws-apigateway LambdaIntegration handles imported aliases and external functions. Run the supplied TypeScript reproduction with Alias.fromAliasAttributes and Function.fromFunctionAttributes; done means LambdaTarget accepts an external function or alias without either permission-validation or IDependable errors.
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
- Clearly specified
- Newbie friendliness
- 42/100