(aws-lambda/aws-cloudfront): FunctionUrls cannot be added to cloudfront as a http origin
See original GitHub issueDescribe the bug
When trying to connect a function url into a cloudfront distribution with a HttpOrigin fails
Resource handler returned message: "Invalid request provided: The parameter origin name cannot contain a colon.
Expected Behavior
I would expect to be able to add a LambdaFunctionURL to Cloudfront
Current Behavior
Deployment fails
❌ LambdaHttp failed: Error: The stack named LambdaHttp failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: The parameter origin name cannot contain a colon. (Service: CloudFront, Status Code: 400, Request ID: 76dfc5ad-2e21-44db-bfd0-023d08d8a427)" (RequestToken: 925d656b-5ec5-f4fb-e0eb-a37db550d1c1, HandlerErrorCode: InvalidRequest)
at prepareAndExecuteChangeSet (/home/blacha/tmp/lambda-http/node_modules/aws-cdk/lib/api/deploy-stack.ts:382:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at CdkToolkit.deploy (/home/blacha/tmp/lambda-http/node_modules/aws-cdk/lib/cdk-toolkit.ts:209:24)
at initCommandLine (/home/blacha/tmp/lambda-http/node_modules/aws-cdk/lib/cli.ts:341:12)
The stack named LambdaHttp failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid request provided: The parameter origin name cannot contain a colon. (Service: CloudFront, Status Code: 400, Request ID: 76dfc5ad-2e21-44db-bfd0-023d08d8a427)" (RequestToken: 925d656b-5ec5-f4fb-e0eb-a37db550d1c1, HandlerErrorCode: InvalidRequest)
Reproduction Steps
Given a lambda and cloudfront distribution, trying to hook them together using a HttpOrigin
const lambda = new NodejsFunction(this, 'Lambda', { entry: './echo.js', })
const functionUrl = new FunctionUrl(this, 'LambdaFunctionUrl', { function: lambda, authType: FunctionUrlAuthType.NONE, cors: { allowedOrigins: ['*'] } })
const cf = new Distribution(this, 'Cloudfront', {
defaultBehavior: {
origin: new origins.HttpOrigin(functionUrl.url),
allowedMethods: AllowedMethods.ALLOW_ALL,
originRequestPolicy: OriginRequestPolicy.ALL_VIEWER
}
})
new CfnOutput(this, 'CloudfrontUrl', { value: cf.distributionDomainName })
new CfnOutput(this, 'LambdaUrl', { value: functionUrl.url })
Possible Solution
No response
Additional Information/Context
I am assuming that HttpOrigin is how you would expect to connect these, I couldnt see anything in github/docs about how to connect a functionurl to cloudfront.
When creating the function url in the AWS Console then manually connecting them it works fine.
CDK CLI Version
2.21.1 (build a6ee543)
Framework Version
No response
Node.js Version
v16.14.2
OS
Ubuntu 22.04 LTS
Language
Typescript
Language Version
Javascript
Other information
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Using various origins with CloudFront distributions
You can use various different origins with Amazon CloudFront, including Amazon ... with function URLs, you can add CloudFront to get the following...
Read more >AWS Cloudfront on Lambda Function via the Function URL url ...
The issue could be that you are forwarding the Host header to your origin (Lambda Function URLs) via the AllViewer Origin Request Policy ......
Read more >How do I resolve the CloudFront error "No Access ... - YouTube
Your browser can't play this video. ... Rishu shows you how to resolve the CloudFront error "No Access-Control-Allow - Origin header.
Read more >Restrictions on edge functions - Amazon CloudFront
Edge functions for viewer response events cannot modify the HTTP status code of the response, regardless of whether the response came from the...
Read more >CloudFront to Lambda URLs - Serverless Land
Front AWS Lamda Function URLs with Amazon CloudFront ... http2 IPV6Enabled: true Comment: Distribution with Lambda Function URL Origins: - DomainName: !
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@blacha - The problem is that Lambda URLs are rejecting requests from CloudFront that have the Host header set to the edge host name and not to the Lambda URL host name.
We were just talking to an AWS PM about this on Friday. Because Lambda URLs use exclusively HTTPS they do not need the Host header for multiplexing of many hosts on single IPs (they will use the SNI for that).
But, currently, including the Host header causes the request to be rejected if it’s not the Lambda URL hostname.
Options:
request.custom.origin.domainName
(IIRC) - This will cause Lambda URL to receive the correct hostname in the header (can confirm this works, it’s a technique I use) - Kind of a lame usage of an origin request lambda…Hope this helps. By the way… you can also sign the origin requests using SignatureV4 from CloudFront using an Origin Request Lambda @ Edge Function then enable AWS_IAM auth on your Lambda URLs. I have projects that are using this technique now, which is part of the reason why I ran into the Host header issue (which is similar for API Gateway).
You can use a custom policy like this: example custom request policy