Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(lambda): Return domain name for Lambda Function Url #20254

Closed
2 tasks
MarkusWendorf opened this issue May 8, 2022 · 6 comments
Closed
2 tasks

(lambda): Return domain name for Lambda Function Url #20254

MarkusWendorf opened this issue May 8, 2022 · 6 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@MarkusWendorf
Copy link

MarkusWendorf commented May 8, 2022

Describe the feature

I've tried to connect my Lambda with a function url endpoint to a CloudFront origin, but the function url only returns the url itself but not the domain name, which is required for an http origin.

Because the url is a token only resolved at synth time, it cannot be modified easily (to return only the domain name).
I had to use a workaround: https://github.com/MarkusWendorf/cdk-function-url

Gist:

const apiDomain = Lazy.uncachedString({
  produce: (context) => {
    const resolved = context.resolve(functionUrl.url);
    return { "Fn::Select": [2, { "Fn::Split": ["/", resolved] }] } as any;
  },
});

That's why I would propose that the FunctionUrl resource also returns the domain name.

Use Case

I've tried to connect my Lambda with a function url endpoint to a CloudFront origin, but the function url only returns the url itself but not the domain name, which is required for a http origin.

Proposed Solution

Return the domainName in addition to the url from the FunctionUrl resource.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.21.1

Environment details (OS name and version, etc.)

Macos 12.3.1

@MarkusWendorf MarkusWendorf added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 8, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label May 8, 2022
@kaizencc kaizencc changed the title Return domain name for Lambda Function Url (lambda): Return domain name for Lambda Function Url May 9, 2022
@kaizencc
Copy link
Contributor

kaizencc commented May 9, 2022

The function url is an attribute returned by cloudformation according to their documentation. I'm not sure that this is achievable on our end as we are bound to cloudformation. We'd have to parse the url as a Lazy string just as you've done, and I'm not sure that's feasible to maintain at the moment.

@kaizencc kaizencc added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 9, 2022
@kaizencc kaizencc removed their assignment May 9, 2022
@Misfits09
Copy link

Misfits09 commented Oct 26, 2022

I encountered the same problem and figured out a similar "trick" to make it work... I ended up using :

origin: new HttpOrigin(Fn.select(2, Fn.split('/', lambdaUrl.url)))

Do you still believe it shouldn't be a feature ? @kaizencc
It should, I think, at least be mentionned somewhere in the documentation of FunctionUrl or HttpOrigin as it is not that uncommon nowadays to want to point Cloudfront to a lambda endpoint...

@Dav3rs
Copy link

Dav3rs commented Jan 24, 2023

@Misfits09 I was able to move forward with your trick, but now I'm stuck with a forbidden when calling the function, how can I grant permissions to make the invocation?

image

@tylerhcarter
Copy link

@Dav3rs You've probably figured this out, but the 403 is likely being caused by the AUTH_TYPE for the URL being defaulted to AWS_IAM, meaning its looking for an AWS Signature in the request.

You can either open up the URL by setting the authentication to none, or you can implement a CloudFront request signer to sign outgoing requests with a role the has been granted the ability to invoke your lambda url.

@watany-dev
Copy link
Contributor

As this ticket has been resolved, it would be appropriate to close it.
#29101

Copy link

github-actions bot commented Mar 7, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

6 participants