Checking both the Terraform cloudfront_function resource and the AWS apis make it look like direct S3 paths aren’t supported and it’s assumed that the function code is available locally.
You may be able to use Terraform Registry to download an S3 object and use that.
I just read the provider documentation for the resource that you linked. If you want more details, the provider source for that resource is here.
file is a built-in Terraform function that reads in the contents of a file and returns it. It’s also possible to inline the actual function code, but properly escaping newlines and such adds complexity; not to mention verbosity.