Skip to content

Commit

Permalink
Release 2.14.0 with CloudFront wildcard inv
Browse files Browse the repository at this point in the history
  • Loading branch information
laurilehmijoki committed Jun 7, 2016
1 parent d034e7c commit 7089b38
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 20 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ cloudfront_distribution_config:
Once you've saved the configuration into `s3_website.yml`, you can apply them by
running `s3_website cfg apply`.

#### Invalidating all CloudFront resources (wildcard invalidation)

The following setting is recommended for most users:

```yaml
cloudfront_wildcard_invalidation: true
```

Over time, it can reduce your AWS bill significantly. For more information, see <http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html>.

#### Invalidating root resources instead of index.htmls

By default, `s3_website push` calls the CloudFront invalidation API with the
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This project uses [Semantic Versioning](http://semver.org).

## 2.14.0

* Add support for CloudFront wildcard invalidations

Introduced a new setting, `cloudfront_wildcard_invalidation: (true|false)`

## 2.13.0

* Add support for `dnf`, a Linux package manager
Expand Down
2 changes: 1 addition & 1 deletion lib/s3_website/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module S3Website
VERSION = '2.13.0'
VERSION = '2.14.0'
end
2 changes: 2 additions & 0 deletions resources/configuration_file_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ s3_bucket: your.blog.bucket.com

# cloudfront_invalidate_root: true

cloudfront_wildcard_invalidation: true

# concurrency_level: 5

# redirects:
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/s3/website/CloudFront.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ object CloudFront {
def awsCloudFrontClient(config: Config) = new AmazonCloudFrontClient(awsCredentials(config))

def toInvalidationBatches(pushSuccessReports: Seq[PushSuccessReport])(implicit config: Config): Seq[InvalidationBatch] = {
def callerReference = s"s3_website gem ${System.currentTimeMillis()}"
if (config.cloudfront_wildcard_invalidation.contains(true) && pushSuccessReports.exists(needsInvalidation)) {
return Seq(new InvalidationBatch withPaths(new Paths withItems "/*" withQuantity 1) withCallerReference callerReference)
}
def defaultPath(paths: Seq[String]): Option[String] = {
// This is how we support the Default Root Object @ CloudFront (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DefaultRootObject.html)
// We could do this more accurately by fetching the distribution config (http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/GetConfig.html)
Expand Down Expand Up @@ -102,8 +106,7 @@ object CloudFront {
.grouped(1000) // CloudFront supports max 1000 invalidations in one request (http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#InvalidationLimits)
.map { batchKeys =>
new InvalidationBatch() withPaths
(new Paths() withItems batchKeys withQuantity batchKeys.size) withCallerReference
s"s3_website gem ${System.currentTimeMillis()}"
(new Paths() withItems batchKeys withQuantity batchKeys.size) withCallerReference callerReference
}
.toSeq
}
Expand Down
35 changes: 18 additions & 17 deletions src/main/scala/s3/website/model/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ import s3.website._
import com.amazonaws.auth.{AWSCredentialsProvider, BasicAWSCredentials, DefaultAWSCredentialsProviderChain}

case class Config(
s3_id: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html)
s3_secret: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html)
s3_bucket: String,
s3_endpoint: S3Endpoint,
site: Option[String],
max_age: Option[Either[Int, S3KeyGlob[Int]]],
cache_control: Option[Either[String, S3KeyGlob[String]]],
gzip: Option[Either[Boolean, Seq[String]]],
gzip_zopfli: Option[Boolean],
s3_key_prefix: Option[String],
ignore_on_server: Option[S3KeyRegexes],
exclude_from_upload: Option[S3KeyRegexes],
s3_reduced_redundancy: Option[Boolean],
cloudfront_distribution_id: Option[String],
cloudfront_invalidate_root: Option[Boolean],
redirects: Option[Map[S3Key, String]],
concurrency_level: Int,
s3_id: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html)
s3_secret: Option[String], // If undefined, use IAM Roles (http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html)
s3_bucket: String,
s3_endpoint: S3Endpoint,
site: Option[String],
max_age: Option[Either[Int, S3KeyGlob[Int]]],
cache_control: Option[Either[String, S3KeyGlob[String]]],
gzip: Option[Either[Boolean, Seq[String]]],
gzip_zopfli: Option[Boolean],
s3_key_prefix: Option[String],
ignore_on_server: Option[S3KeyRegexes],
exclude_from_upload: Option[S3KeyRegexes],
s3_reduced_redundancy: Option[Boolean],
cloudfront_distribution_id: Option[String],
cloudfront_invalidate_root: Option[Boolean],
redirects: Option[Map[S3Key, String]],
concurrency_level: Int,
cloudfront_wildcard_invalidation: Option[Boolean],
treat_zero_length_objects_as_redirects: Option[Boolean]
)

Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/s3/website/model/Site.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object Site {
cloudfront_distribution_id <- loadOptionalString("cloudfront_distribution_id").right
cloudfront_invalidate_root <- loadOptionalBoolean("cloudfront_invalidate_root").right
concurrency_level <- loadOptionalInt("concurrency_level").right
cloudfront_wildcard_invalidation <- loadOptionalBoolean("cloudfront_wildcard_invalidation").right
redirects <- loadRedirects(s3_key_prefix).right
treat_zero_length_objects_as_redirects <- loadOptionalBoolean("treat_zero_length_objects_as_redirects").right
} yield {
Expand Down Expand Up @@ -78,6 +79,7 @@ object Site {
cloudfront_invalidate_root,
redirects,
concurrency_level.fold(20)(_ max 20),
cloudfront_wildcard_invalidation,
treat_zero_length_objects_as_redirects
)
}
Expand Down

0 comments on commit 7089b38

Please sign in to comment.