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): Add domain helper prop to FunctionUrl #23005

Open
1 of 2 tasks
diesal11 opened this issue Nov 21, 2022 · 2 comments · May be fixed by #30198
Open
1 of 2 tasks

(lambda): Add domain helper prop to FunctionUrl #23005

diesal11 opened this issue Nov 21, 2022 · 2 comments · May be fixed by #30198
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@diesal11
Copy link
Contributor

diesal11 commented Nov 21, 2022

Describe the feature

The lambda.FunctionUrl construct currently returns the Function URL as a full URL including the scheme + trailing /.

https://*******.lambda-url.ap-southeast-2.on.aws/

In many cases, it's preferable to have just the domain name.

*******.lambda-url.ap-southeast-2.on.aws

Use Case

When serving a Function URL through a Cloudfront Distribution. The following workaround is required to remove the URL Scheme and path from fn_url.url so it can be consumed by Cloudfront.HttpOrigin

fn_url = function.add_function_url(
    auth_type=lmbda.FunctionUrlAuthType.NONE,
)

# This removes the URL Scheme and trailing `/` from the Function URL`
# leaving: "*******.lambda-url.ap-southeast-2.on.aws"
fn_url_domain = Fn.select(
    0, Fn.split("/", Fn.select(1, Fn.split("https://", fn_url.url)))
)

distribution = cf.Distribution(
    self,
    "distribution",
    default_behavior=cf.BehaviorOptions(
        origin=cfo.HttpOrigin(fn_url_domain),
    )
)

Proposed Solution

The above code be added as a helper function on FunctionUrl construct:

fn_url_domain = Fn.select(
    0, Fn.split("/", Fn.select(1, Fn.split("https://", fn_url.url)))
)

Other Information

Happy to implement this one if it's a wanted change. Open to any suggestions on code or property names etc.

Acknowledgements

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

CDK version used

2.50.0

Environment details (OS name and version, etc.)

MacOS 13

@diesal11 diesal11 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 21, 2022
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Nov 21, 2022
@diesal11 diesal11 changed the title (lambda): Add domain helper prop (lambda): Add domain helper prop to FunctionUrl Nov 21, 2022
@peterwoodworth
Copy link
Contributor

The return value here comes from CloudFormation -

this.url = resource.attrFunctionUrl;

We could add the domain prop to FunctionUrl using the same workaround you're using with intrinsic functions, thanks for the feature request 🙂

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Nov 21, 2022
@diesal11
Copy link
Contributor Author

diesal11 commented Nov 23, 2022

I've opened #23046 which adds this functionality + a unit test.

@mbfreder mbfreder linked a pull request May 15, 2024 that will close this issue
1 task
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/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
3 participants