PHPackages                             troisiemejoueur/cloudfront-signed-urls - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. troisiemejoueur/cloudfront-signed-urls

ActiveCraft-plugin[File &amp; Storage](/categories/file-storage)

troisiemejoueur/cloudfront-signed-urls
======================================

Create AWS Cloudfront Signed Urls for S3 Craft CMS storage

1.2.1(9mo ago)03.4k1MITPHP

Since Feb 22Pushed 9mo agoCompare

[ Source](https://github.com/3ejoueur/craftcms-cloudfront-signed-urls)[ Packagist](https://packagist.org/packages/troisiemejoueur/cloudfront-signed-urls)[ RSS](/packages/troisiemejoueur-cloudfront-signed-urls/feed)WikiDiscussions develop Synced 3w ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

[![Cloudfront Signed URLs icon](./src/icon.svg)](./src/icon.svg)

Cloudfront Signed URLs for Craft CMS
====================================

[](#cloudfront-signed-urls-for-craft-cms)

This plugin provides AWS Cloudfront Signed URLs in Twig templates.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.x

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require troisiemejoueur/cloudfront-signed-urls

    ```
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Cloudfront Signed URLs.

Overview
--------

[](#overview)

This plugin adds a Twig function to sign URLs from an AWS Cloudfront distribution. The common usage is for a restricted section for logged-in users only.

In order to use this plugin, we assume that you already worked with AWS and that you know how to create a bucket, a Cloudfront distribution and an IAM access for the CMS. If not, you can read the documentation of the first-party plugin [AWS S3 plugin from Pixel &amp; Tonic](https://plugins.craftcms.com/aws-s3) and this [article from Andrew Welch](https://nystudio107.com/blog/using-aws-s3-buckets-cloudfront-distribution-with-craft-cms).

**Please, do not open issues for AWS configuration problems or questions that are not related to this plugin.**

How it works
------------

[](#how-it-works)

You upload your assets to a non-public S3 bucket with a Cloudfront distribution with the `Restrict Viewer Access` setting to `Yes`. When you create URLs in your templates, these URLs are signed with a random key.

These URLs are created on page load and expires after the duration that you entered.

[Documentation for Cloudfront Signed URLs](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls.html)

Configuration file
------------------

[](#configuration-file)

The plugin comes with a `config.php` file that defines some sensible defaults.

If you want to set your own values, you should create a `cloudfront-signed-urls.php` file in your Craft config directory. The contents of this file will be merged with the plugin defaults. You only need to specify the values of the settings you want to override.

#### keyPairId

[](#keypairid)

`keyPairId` is where you define the value of *the Key-Pair-Id* field from your *public–private* key pair. [See AWS documentation for creating public–private key pair](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs).

#### cloudfrontDistributionUrl

[](#cloudfrontdistributionurl)

`cloudfrontDistributionUrl` is where you define the base URL for your signed URLs. If you want to manage the base URL on a per-file basis, do not add this setting to your config file. If you are using a subfolder, you can append it to this URL. *Trailing slash are not required*.

#### profile

[](#profile)

`profile` is where you define the profile of your Cloudfront client. `default` is the default value.

#### version

[](#version)

`version` is where you define the version of your Cloudfront client. `2020-05-31` is the default value.

#### region

[](#region)

`region` is where you define the regional endpoint for your Cloudfront client. `ca-central-1` is the default value, you probably need to change it based on your project.

#### defaultExpires

[](#defaultexpires)

`defaultExpires` is where you define in seconds the expiry delay for your signed URLs if not configured as an argument when using the Twig function. This is a fallback value. The default value is 3600 (60 minutes).

The expiry time is calculated like this: `now time` + `defaultExpires`.

**Note:** You can use values from your ENV file for all the configuration settings. Example: `App::env('YOUR_VARIABLE_NAME')`

Example cloudfront-signed-urls.php Config File
----------------------------------------------

[](#example-cloudfront-signed-urlsphp-config-file)

```
