(aws-cloudfront): CloudFront `IFunction` interface is structurally compatible with Lambda's `IFunction`, but not compatible in AWS
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### What is the problem?
I am able to assign a Lambda function to CloudFront function (matching TypeScript interfaces), but when the solution is deployed, it produces an error, as Lambda functions cannot be used as CloudFront functions.
### Reproduction Steps
```ts
new cloudfront.Distribution(this, "CloudFrontDistribution", {
defaultBehavior: {
origin: new S3Origin(bucket),
functionAssociations: [
{
// this does not result in error
function: new NodejsFunction(this, "Fn", {
entry: 'cf.js',
}),
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST
}
]
},
})
```
### What did you expect to happen?
Interfaces to be incompatible and get an error in the IDE and at build time.
### What actually happened?
No error was produced in the IDE or at build time.
Error happened during the deployment:
> Invalid request provided: 2 validation errors detected: Value 'arn:aws:lambda:ap-northeast-1:123456:function:Fn220341F76-xxx' at 'distributionConfig.cacheBehaviors.items.1.member.functionAssociations.items.1.member.functionARN' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:aws:cloudfront::[0-9]{12}:function\/[a-zA-Z 0-9-_]{1,64}$; Value 'arn:aws:lambda:ap-northeast-1:123456:function:Fn220341F76-h4X9p0uP7M5E' at 'distributionConfig.cacheBehaviors.items.1.member.functionAssociations.items.1.m ember.functionARN' failed to satisfy constraint: Member must have length less than or equal to 108 (Service: CloudFront, Status Code: 400, Request ID: 5fcc4d15-74b0-4a55-9845-8631a395fdb2, Extended Request ID: null)"
### CDK CLI Version
1.126.0 (build f004e1a)
### Framework Version
1.126.0
### Node.js Version
v14.17.5
### OS
macOS
### Language
Typescript
### Language Version
TypeScript 4.4.3
### Other information
_No response_
Contributor guide
Research direction
Start at the CloudFront Distribution functionAssociations entry point and compare the CloudFront and Lambda IFunction types used by the TypeScript API. Add a compile-time regression test for assigning a Lambda function there, and verify that the documented reproduction is rejected before deployment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100