Skip to content

vendor_connectors.aws.s3

AWS S3 operations.

This module provides operations for working with S3 buckets and objects.

AWSS3MixinMixin providing AWS S3 operations.

Mixin providing AWS S3 operations.

This mixin requires the base AWSConnector class to provide:

  • get_aws_client()
  • get_aws_resource()
  • logger
  • execution_role_arn

List all S3 buckets.

Args: unhump_buckets: Convert keys to snake_case. Defaults to True. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Dictionary mapping bucket names to bucket data.

Get the region of an S3 bucket.

Args: bucket_name: Name of the S3 bucket. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The AWS region where the bucket is located.

Get an object from S3.

Args: bucket: S3 bucket name. key: S3 object key. decode: Decode bytes to string. Defaults to True. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The object contents, or None if not found.

Get a JSON object from S3.

Args: bucket: S3 bucket name. key: S3 object key. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The parsed JSON object, or None if not found.

Put an object to S3.

Args: bucket: S3 bucket name. key: S3 object key. body: Object content. content_type: Content-Type header. Auto-detected if not provided. metadata: Optional metadata to attach to object. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The S3 put_object response.

Put a JSON object to S3.

Args: bucket: S3 bucket name. key: S3 object key. data: Data to serialize to JSON. indent: JSON indentation. Defaults to 2. metadata: Optional metadata to attach to object. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The S3 put_object response.

Delete an object from S3.

Args: bucket: S3 bucket name. key: S3 object key. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The S3 delete_object response.

List objects in an S3 bucket.

Args: bucket: S3 bucket name. prefix: Key prefix to filter by. delimiter: Delimiter for hierarchical listing. max_keys: Maximum number of keys to return. unhump_objects: Convert keys to snake_case. Defaults to True. execution_role_arn: ARN of role to assume for cross-account access.

Returns: List of object metadata dictionaries.

Copy an object within S3.

Args: source_bucket: Source bucket name. source_key: Source object key. dest_bucket: Destination bucket name. dest_key: Destination object key. execution_role_arn: ARN of role to assume for cross-account access.

Returns: The S3 copy_object response.

Get bucket configuration features (logging, versioning, lifecycle, policy).

Args: bucket_name: S3 bucket name. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Dictionary with logging, versioning, lifecycle_rules, and policy.

Find S3 buckets with names containing a string.

Args: name_contains: Substring to search for in bucket names. include_features: Include bucket features for each match. Defaults to False. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Dictionary mapping bucket names to bucket data/features.

Create an S3 bucket.

Args: bucket_name: Bucket name (must be globally unique). region: AWS region. Uses default if not specified. acl: Bucket ACL. Defaults to ‘private’. enable_versioning: Enable versioning. Defaults to False. tags: Optional tags to apply. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Create bucket response.

Delete an S3 bucket.

Args: bucket_name: Bucket name. force: Delete all objects first. Defaults to False. execution_role_arn: ARN of role to assume for cross-account access.

Raises: ClientError: If bucket not empty and force=False.

Get tags for an S3 bucket.

Args: bucket_name: Bucket name. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Dictionary of tag key-value pairs.

Set tags for an S3 bucket.

Args: bucket_name: Bucket name. tags: Dictionary of tag key-value pairs. execution_role_arn: ARN of role to assume for cross-account access.

Get sizes of S3 buckets using CloudWatch metrics.

Args: bucket_names: Specific buckets to check. All buckets if None. execution_role_arn: ARN of role to assume for cross-account access.

Returns: Dictionary mapping bucket names to size info (bytes, object_count).