meema/laravel-cloudfront

Easily & quickly integrate your application with AWS CloudFront.

1.0.0 2021-03-21 01:20 UTC

This package is auto-updated.

Last update: 2024-10-20 04:05:16 UTC


README

Latest Version on Packagist GitHub Workflow Status StyleCI Scrutinizer Code Quality Total Downloads Discord License

This is a wrapper package for AWS CloudFront. Please note that while this package is used in production environments and is completely functional, it currently only focuses on cache invalidations.

PRs & ideas are more than welcome! ๐Ÿ™๐Ÿผ

laravel-cloudfront package image

๐Ÿ’ก Usage

use Meema\CloudFront\Facades\CloudFront;
use Meema\CloudFront\Jobs\InvalidateCache;

// run any of the following CloudFront methods:
$client = CloudFront::getClient(); // exposes the AWS CloudFront client

$paths = ['/some-path.jpg', '/another/path.png'];
$result = CloudFront::invalidate($paths, string $distributionId = null);

// invalidates everything, which is the equivalent to a item path of `/*`.
$result = CloudFront::reset();

$message = CloudFront::getInvalidation(string $invalidationId, string $distributionId = null);
$messages = CloudFront::listInvalidations(string $distributionId = null);

// it's recommended to invalidate your cache using a job
dispatch(new InvalidateCache($path.'*')); // you may want to add a '*'-wildcard at the end of your path if you whitelisted any query parameters

Please note, object invalidations typically take from 60 to 300 seconds to complete. You can check the status of an invalidation by viewing your distribution from the CloudFront console.

๐Ÿ™ Installation

You can install the package via composer:

composer require meema/laravel-cloudfront

The package will automatically register itself.

Next, publish the config file with:

php artisan vendor:publish --provider="Meema\CloudFront\Providers\CloudFrontServiceProvider" --tag="config"

Next, please add the following keys their values to your .env file.

AWS_ACCESS_KEY_ID=xxxxxxx
AWS_SECRET_ACCESS_KEY=xxxxxxx
AWS_CLOUDFRONT_DISTRIBUTION_ID=xxxxxxx

The following is the content of the published config file:

return [
    /**
     * IAM Credentials from AWS.
     */
    'credentials' => [
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
    ],

    'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),

    /**
     * Specify the version of the CloudFront API you would like to use.
     * Please only adjust this value if you know what you are doing.
     */
    'version' => 'latest',

    /**
     * Specify the CloudFront Distribution ID.
     * Example format: EBCYQAQALNSKL
     */
    'distribution_id' => env('AWS_CLOUDFRONT_DISTRIBUTION_ID'),

];

๐Ÿงช Testing

composer test

๐Ÿ“ˆ Changelog

Please see our releases page for more information on what has changed recently.

๐Ÿ’ช๐Ÿผ Contributing

Please see CONTRIBUTING for details.

๐Ÿ Community

For help, discussion about best practices, or any other conversation that would benefit from being searchable:

Laravel CloudFront on GitHub

For casual chit-chat with others using this package:

Join the Meema Discord Server

๐Ÿšจ Security

Please review our security policy on how to report security vulnerabilities.

๐Ÿ™๐Ÿผ Credits

๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE for more information.

Made with โค๏ธ by Meema, Inc.