Configure skygear with AWS cloudfront


#1

Hello,

We’re currently using AWS S3 to serve all our images from S3 bucket.
I have created a Cloudfront distribution.

So now I want the default asset url to be updated from:
https://s3-ap-southeast-1.amazonaws.com/tailorm-product/8f6f058c-7c69-4e40-bb72-48421cc07688-image.jpg
to
https://d23gkjp7j5kjfe.cloudfront.net/8f6f058c-7c69-4e40-bb72-48421cc07688-image.jpg

We need to be able to continue uploading files to S3 bucket, but for displaying the files on web, we need to use the cloudfront URL. I don’t see support for this in the skygear config. However if this is possible, how do we configure this in docker-skygear.env ?

Currently our settings is like:
ASSET_STORE=s3
ASSET_STORE_PUBLIC=YES
ASSET_STORE_PATH=data/asset
ASSET_STORE_URL_PREFIX=http://localhost:3000/files
ASSET_STORE_SECRET=xxxxx
ASSET_STORE_ACCESS_KEY=xxxxx
ASSET_STORE_SECRET_KEY=xxxxx
ASSET_STORE_REGION=ap-southeast-1
ASSET_STORE_BUCKET=tailorm-dev


#2

#3

I guess the question is … is there a function that can use an alternative url ?

We get images like this currently, and this returns the AWS S3 path.

style={{‘backgroundImage’: ‘url(skygearAssetUrl(tailorInfo.logo_image)’}}

How can we get the asset but use the cloudfront URL ?


#4

For using ASSET_STORE with cloudfront, you can use replace ASSET_STORE_S3_URL_PREFIX with the clouffront URL.

Like this.

ASSET_STORE=s3
ASSET_STORE_PUBLIC=YES
ASSET_STORE_ACCESS_KEY=xxxxx
ASSET_STORE_SECRET_KEY=xxxxx
ASSET_STORE_REGION=ap-southeast-1
ASSET_STORE_BUCKET=tailorm-dev
ASSET_STORE_S3_URL_PREFIX=https://d23gkjp7j5kjfe.cloudfront.net

I remove the evvvar for FS store and leave only S3 related ENVVAR


#5

Cool, it works, thanks!