Skip to content

Commit 090daa8

Browse files
authored
Add cache control if aws site cdn default ttl is set (#26)
* fix s3 cache-control * fix dynamic block * cache-control * Fix-cache-control * Bump README
1 parent 39b8550 commit 090daa8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868

6969
steps:
7070
- name: Create deploy-bucket
71-
uses: bitovi/github-actions-deploy-static-site-to-aws@v0.2.7
71+
uses: bitovi/github-actions-deploy-static-site-to-aws@v0
7272
with:
7373
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
7474
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -98,7 +98,7 @@ jobs:
9898
runs-on: ubuntu-latest
9999
steps:
100100
- name: Create deploy-bucket
101-
uses: bitovi/github-actions-deploy-static-site-to-aws@v0.2.7
101+
uses: bitovi/github-actions-deploy-static-site-to-aws@v0
102102
with:
103103
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
104104
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -125,7 +125,7 @@ jobs:
125125
runs-on: ubuntu-latest
126126
steps:
127127
- name: Create deploy-bucket
128-
uses: bitovi/github-actions-deploy-static-site-to-aws@v0.2.7
128+
uses: bitovi/github-actions-deploy-static-site-to-aws@v0
129129
with:
130130
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
131131
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -271,6 +271,7 @@ For deployments or applications that rotate files on each deployment, the defaul
271271
- **`aws_site_cdn_max_ttl`**: Set to 365 days (31536000 seconds)
272272

273273
These settings allow CloudFront to cache files even after they've been deleted from S3, reducing 404 errors during deployment transitions. Files remain cached at edge locations for the specified TTL period, giving users time to gradually transition to the new version.
274+
Additionally, each uploaded object includes a `cache_control` header that matches the value of `aws_site_cdn_default_ttl`.
274275

275276
Example with custom TTL settings:
276277

terraform_code/s3.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ module "template_files" {
5454
base_dir = var.aws_site_source_folder
5555
}
5656

57-
# Will upload each file to the bucket, defining content-type
5857
resource "aws_s3_object" "aws_site_website_bucket" {
5958
for_each = module.template_files.files
6059

@@ -66,6 +65,8 @@ resource "aws_s3_object" "aws_site_website_bucket" {
6665
content = each.value.content
6766

6867
etag = each.value.digests.md5
68+
69+
cache_control = var.aws_site_cdn_default_ttl > 0 ? "public, max-age=${var.aws_site_cdn_default_ttl}" : null
6970
}
7071

7172
### IAM Policies definitions

0 commit comments

Comments
 (0)