semvec/pypi-packages huggingface dataset:
fastapi-cloud-healthcheck-aws-s3bucket 0.1.1
This package is designed to validate the operational status of Amazon S3 buckets within an AWS account. It provides comprehensive diagnostics on the accessibility and functionality of an S3 bucket by performing key operations, including Bucket Accessibility, Object Operations and Bucket Policy Validation.
License: MIT
Requires Python: <4.0,>=3.8
Keywords: fastapi, healthcheck, cloud, boto3, aws, s3, storage

# fastapi_cloud_healthcheck_aws_s3bucket

A FastAPI-based health check module for monitoring the health of AWS S3 buckets using the `fastapi_cloud_healthcheck` package.

## Features

* Bucket Accessibility: Verifies if the S3 bucket exists and is accessible within the given AWS region.
* Object Operations: Performs test operations such as uploading, reading, and deleting objects within the bucket to ensure correct permissions.
* Bucket Policy Validation: Checks for the presence of an S3 bucket policy and its retrieval status.
* Automated Account Detection: Automatically retrieves the AWS Account ID for the health check metadata.

## Adding Health Checks

Here is a sample FastAPI application that integrates the S3 bucket health check:

```python
from fastapi import FastAPI
from fastapi_cloud_healthcheck import HealthCheckFactory, create_health_check_route
from fastapi_cloud_healthcheck_aws_s3bucket import HealthCheckS3Bucket

app = FastAPI()

# Create Health Check Factory
health_check_factory = HealthCheckFactory()

# Add the S3 Bucket Health Check
health_check_factory.add(
    HealthCheckS3Bucket(
        bucket_name="my-sample-bucket",
        region="us-west-1"
    )
)

# Add the health check route to FastAPI
app.add_api_route('/health', endpoint=create_health_check_route(factory=health_check_factory))

```

In the above example:
- We create a health check for the S3 bucket named `my-sample-bucket` in the region `us-west-1`. 
- The health check endpoint `/health` will expose detailed health information about the S3 bucket.

## Health Check Process
The **S3 Bucket Health Check** performs the following operations:

1. **Bucket Accessibility**: Uses the `head_bucket` boto3 API to check if the bucket exists and is accessible.
  
2. **Test Object Operations**:
    - **Upload**: Uploads a temporary object to the bucket.
    - **Read**: Retrieves and validates the content of the test object.
    - **Cleanup**: Deletes the test object after validation.
  
3. **Bucket Policy Check**: Ensures the bucket policy is accessible by attempting to retrieve it.
4. **MultiPart Object Upload**: 
   - **Initiation**: Starts a multipart upload for a test object.
   - **Abortion**: Immediately aborts the multipart upload to verify that the multipart upload feature is functional.