S3 Utils
Module for downloading images from S3 URLs.
This module provides a class for downloading file from S3 URLs.
It will first try to connect using default credentials (instance profile, environment variables, etc), and if that fails, it will explicitly check for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. If those fail, it will check for AWS_SESSION_TOKEN.
get_file_from_s3(url)
Get file from S3 bucket.
This function attempts to get a file from an S3 bucket using: 1. Default credentials (from AWS CLI or instance profile). 2. Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). 3. Session token if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The S3 URL to get the file from. Can be in the format: 1. s3://bucket/key. 2. https://bucket.s3.amazonaws.com/key. |
required |
Returns:
| Type | Description |
|---|---|
bytes | None
|
bytes | None: The file contents if successful, None otherwise |
Raises:
| Type | Description |
|---|---|
ValueError
|
If AWS credentials are not found or invalid. |