In this article you will learn how to:
- Create Amazon S3 bucket
- Setup CloudFront distribution
- Create user and give permission to access S3 bucket
- Configure Kentico Instance to use Amazon S3 and CloudFront as a external storage
Before I start, I assume you already logged in to Amazon Cloud Console dashboard.
Create Amazon S3 bucket
- Navigate to Amazon s3 services.
- Hit “Create bucket” button.
- Give name to the bucket. eg : demo-web
- Set AWS Region to your nearest region. In this example I will use Asia Pasific (Singapore) ap-southeast-1 region
- Under Object ownership Choose ACLs enabled and Object Ownership set to Bucket owner preferred.
- Set Public Access setting for this bucket as per image below.
- Set bucket Versioning to disable
- Tags is optional, you can set the tag for this bucket for easy reference in the future, I will skip this option.
- Set default encryption to disable
- Hit “Create bucket” button.
Setup CloudFront distribution
- Navigate to CloudFront Services
- Hit “Create distribution” button
- Select Origin Domain with S3 bucket we just create.
- Leave origin path & Name to empty
- Set Enable Origin Field to No
- Set Path Pattern to Default(*)
- Set Compress objects automatically to Yes
- Viewer protocol policy set to “Redirect HTTP to HTTPS”
- Allow HTTP method set to “GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE” and select OPTION method also
- Restrict viewer access set to No
- Cache key and origin request set to Cache policy and origin request policy (recommended)
- Cache Policy set to “CachingOptimized”
- Leave all other fields to default value and Hit “Create distribution” button.
Once Done, click on the distribution we just created and navitage to Origins tab
- Select the origin we just created and click Edit button
- Go to the S3 bucket access
- Choose “Yes use OAI (bucket can restrict access to only CloudFront)”
- Select Origin access identity – Create new OAI if you don’t have any OAI
- select bucket policy to “Yes, update the bucket policy”.
- Click Save changes
Create user and give permission to access S3 bucket
- Navigate to IAM services.
- Click Users under Access management menu
- Click Add users button
- Insert user name value. eg: S3_user_demo
- Select AWS credential type to Access key – Programmatic access
- Select Permission to “Attach existing policies directly”
- Fillter policies to S3 – Choose AmazonS3FullAccess policies
- Click Next : Tags button
- Leave it empty, you can set tags for future reference. – click Next : Review button
- Click Create User button
- Copy Access key ID and Secret access key or you can download in .csf file to you computer.
Configure Kentico Instance to use Amazon S3 and CloudFront as a external storage
- Open web.config in your Kentico Instance
- Under appSettings add keys below: –
- <add key=”CMSExternalStorageName” value=”amazon”/>
- <add key=”CMSAmazonAccessKeyID” value=”<Access key ID>” />
- <add key=”CMSAmazonAccessKey” value=”<secret key> />
- <add key=”CMSAmazonBucketName” value=”<Your bucket name>” />
- <add key=”CMSAmazonPublicAccess” value=”true” />
- <add key=”CMSAmazonEndPoint” value=”https://<cloudfront domain>” />
- You can get Access key id and secret key at step when you create user to access S3 bucket.
- Bucket name you can get when you create S3 bucket, in this example bucket name is “demo-web”
- CloudFront domain you can get when you finished create CloudFront Distribution.
- Once finish configure web.config. Login to kentico backend and go to Setting module.
- Navigate to System >> Files. Make sure Store files in set to File System.
- Navigate to System >> Performance. Tick Redirect files to disk. Click Save.
*You can refer on Kentico documentation more on how to configure Kentico to use Amazon S3 bucket as external storage.
Once done all process above. you can test from kentico Media Library module to upload, delete and update file.
You should be able to get cloudfront domain with path of the file once upload file finish to indicate the configuration is successfull.
Good luck, Happy coding.!