silverstripe / silverstripe-s3

Silverstripe module to store assets in S3 rather than on the local filesystem (SS4/SS5 only)
BSD 3-Clause "New" or "Revised" License
20 stars 25 forks source link

Support Cloudfront #25

Closed mngreece closed 5 years ago

mngreece commented 5 years ago

Support for having a CloudFront distribution that has a s3 bucket for assets behind the distribution and only requests for public assets and can only be accessed from CloudFront, i.e. https://some-domain.com/assets/

At the moment public the URL returned is always https://.s3...amazonaws.com/xxxxx

obj63mc commented 5 years ago

You should be able to do this by specifying an options variable in your yaml config for the public adapter defining the base_url https://flysystem.thephpleague.com/docs/adapter/aws-s3/

Would be something like

SilverStripe\S3\Adapter\PublicAdapter:
constructor:
  s3Client: '%$Aws\S3\S3Client'
  bucket: '`AWS_BUCKET_NAME`'
  prefix: '`AWS_PUBLIC_BUCKET_PREFIX`'
  options:
     - base_url: 'https://....'

You could also extend the PublicAdapter class and change the getUrl function I believe

mngreece commented 5 years ago

I've extended the PublicAdapter but will try out the config option above - thanks.

zanderwar commented 4 years ago

@obj63mc

Could you double check that please? I've tried many variations but the base_url is never used despite evidently being passed through to the options parameter

JoshuaCarter commented 3 years ago

For anyone who stumbles on this, I found this worked:

SilverStripe\Core\Injector\Injector:
  Aws\S3\S3Client:
    constructor:
      configuration:
        endpoint: https://s3.{region}.{host}.com

Where host is amazonaws, or wasabisys, etc.