(lambda): Add `domain` helper prop to FunctionUrl
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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`
```python
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
- [X] 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
Contributor guide
Assessment
This issue has not been assessed yet.