Skip to content

feat(static-site): allow optional S3 bucket prefix for static site origin#28

Open
nacholiya wants to merge 5 commits intoScript47:masterfrom
nacholiya:feature/static-site-bucket-prefix
Open

feat(static-site): allow optional S3 bucket prefix for static site origin#28
nacholiya wants to merge 5 commits intoScript47:masterfrom
nacholiya:feature/static-site-bucket-prefix

Conversation

@nacholiya
Copy link
Contributor

Summary

Adds support for an optional bucket_prefix variable to allow serving static site content from a specific prefix inside the S3 bucket.

Changes

Added bucket_prefix variable

Updated CloudFront origin configuration to support prefix using origin_path

Backward Compatibility

If bucket_prefix is empty (default), the module behaves exactly as before and serves content from the root of the bucket.

Related Issue

Fixes #12

@Script47
Copy link
Owner

bucket_prefix might imply a prefix being added to the bucket itself.

Any other names you can think of?

@nacholiya
Copy link
Contributor Author

nacholiya commented Mar 16, 2026

Good catch 👍 Renamed bucket_prefix to origin_path to better align with CloudFront terminology and avoid confusion.

@Script47
Copy link
Owner

origin_path is much better.

I've been mulling this change over for the last couple of days and have concluded that the real benefit of this change will be seen if you're able to reuse S3 buckets.

Currently, the module always creates the S3 bucket but if you could pass it an existing bucket alongside the origin_path it would allow you setup static sites where the source files can be organised neatly under a single bucket e.g.

  • mysite.com -> mysite/root/index.html (bucket/prefix)
  • subdomain.mysite.com -> mysite/subdomain.mysite.com/index.html
  • another.mysite.com -> mysite/another.mysite.com/index.html

@Script47 Script47 force-pushed the master branch 2 times, most recently from e236168 to 29e930a Compare March 19, 2026 11:42
@nacholiya
Copy link
Contributor Author

Great suggestion 👍 This makes a lot of sense, especially for reusing a single S3 bucket across multiple sites.

I’ll work on adding support for using an existing bucket alongside origin_path.

@nacholiya
Copy link
Contributor Author

Added support for using an existing S3 bucket via existing_bucket_name while preserving current behavior when not provided 👍

@Script47
Copy link
Owner

@nacholiya

I’d approach it like this:

  • Use the existing bucket_name variable to specify the bucket name
  • Add an additional boolean flag, create_bucket, defaulting to true, which can be toggled to determine whether the module should create a new bucket or use an existing one

To me, this is more idiomatic as it provides a single source for the bucket name and an explicit, toggleable flag to control the behaviour.

Of course, you'll need to tweak the logic elsewhere too.

@nacholiya
Copy link
Contributor Author

That makes sense 👍 Using bucket_name with a create_bucket flag is definitely cleaner and more flexible.

I’ll refactor the implementation accordingly.

@nacholiya
Copy link
Contributor Author

Updated variable description to clarify behavior with create_bucket 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[static-site] bucket prefix

2 participants