Package: bucket-dir
bucket-dirbucket-diris a utility for generating a browsable directory tree for an AWS S3 bucket.It was built in order to host Maven and Ivy repositories in S3 and serve them via CloudFront, but it could meet other needs too.Installationpip install bucket-dirUsageRunbucket-dirwith the name of the bucket you wish to index as a parameter:bucket-dir foo-bucketIf you only want to upload indexes for a particular part of the bucket, use--target-path. This will generate indexes for folders that lead to the path, and everything under the path:# These all update the root index, foo-folder's index, and everything underneath foo-folder
bucket-dir foo-bucket --target-path '/foo-folder/foo-object'
bucket-dir foo-bucket --target-path '/foo-folder/'
bucket-dir foo-bucket --target-path 'foo-folder/foo-object'
bucket-dir foo-bucket --target-path 'foo-folder/'If you need to exclude objects with certain names from the index use--exclude-object. This will hide any objects that match this name.index.htmlobjects are ignored for free:bucket-dir foo-bucket --exclude-object 'error.html' --exclude-object 'foo-object'Usebucket-dir --helpfor all arguments.Be sure to provide the command with credentials that allow it to perform ListBucket and PutObject calls against the bucket. E.g. withaws-vault:aws-vault exec foo-profile -- bucket-dir foo-bucketIAM requirementsThis example demonstrates the most restrictive policy you can apply to the principal (e.g. an IAM user or role) that is going to runbucket-dir. Substitutefoo-bucketfor the name of your bucket:{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::foo-bucket"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::foo-bucket/index.html",
                "arn:aws:s3:::foo-bucket/*/index.html"
            ]
        }
    ]
}s3:ListBucketis required forbucket-dirto be able to map out the folders and objects that the bucket contains.s3:PutObjectis required forbucket-dirto be able to upload generatedindex.htmldocuments.s3:DeleteObjectis required forbucket-dirto be able to remove redundantindex.htmldocuments.Example AWS configurationFor examples on how you can configure an S3 bucket to serve static site content indexed bybucket-dir, see:Configuring a public S3 Bucket for use with bucket-dir.Examples of how you can front public and private buckets with CloudFront, and how bucket-dir can be run in a lambda, will be added in due course.Using bucket-dir as a librarybucket-dircan also be used as a dependency of your own python applications.from bucket_dir import BucketDirGenerator

BucketDirGenerator(bucket_name="foo-bucket", site_name="my static site").generate()Character supportbucket-dirsupports objects using any of theSafe characterslisted in the S3object key naming guidelines.The exception to the above rule is using forward slashes consecutively (e.g.my-folder//my-object). This results in a folder called/, which breaks hyperlinks.Use of characters in theCharacters that might require special handlinglist is currently unsupported but is theoretically ok.Some characters inCharacters to avoidmay also work, but you're on your own.DevelopmentStart withmake init. This will install prerequisties and set up a poetry managed virtual environment containing all the required runtime and development dependencies.Unit testing can be performed withmake test. If you want to run pytest with other options, usepoetry run pytest ....You can execute the source code directly withpoetry run bucket-dir.Finally, you can build withmake build. This will update dependencies, run security checks and analysis and finally package the code into a wheel and archive.Publishing can be performed withmake publish, but this is only intended to run in CI on commit to the main branch. If running locally, you need to have PyPI credentials set as env vars.For other rules, see theMakefile.If you are a collaborator, feel free to make changes directly to the main branch. Otherwise, please raise a PR. Don't forget to bump the version inpyproject.toml.ProfilingTo get a performance profile, use:make profileYou must have thegraphvizlibrary installed.Acombined.svgimage will be generated in theprofdirectory which you can use to find bottlenecks and potential enhancements.LicenseThis code is open source software licensed under theApache 2.0 License.