Skip to main content

CloudSpark is a powerful Python package designed to simplify the management of AWS S3 and Lambda services. Whether you're working on the frontend or backend, CloudSpark provides an intuitive interface to generate presigned URLs and handle file uploads seamlessly.

Project description

CloudSpark

cloudspark is a Python package that provides a convenient way to manage AWS S3 buckets and generate presigned URLs using boto3. It supports bucket creation, CORS management, policy setting, and presigned URL generation.

Features

  • S3 Management: Effortlessly manage your S3 buckets, objects, and file uploads with built-in methods.

  • Presigned URL Generation: Generate secure presigned URLs for your S3 objects, enabling users to upload files directly from the frontend without exposing your credentials.

  • Seamless Integration: Designed to work smoothly with both frontend and backend applications, making file uploads and cloud function management more accessible.

This repository contains several components. For more details on each component, refer to the respective README files.

Installation

You can install cloudspark via pip. Make sure you have boto3 installed as well.

pip install cloudspark 

Usage

Importing the Library

from cloudspark import S3Connection

Initializing the Connection

Create an instance of S3Connection by providing your AWS credentials and region name

s3_conn = S3Connection(access_key='YOUR_ACCESS_KEY',

                       secret_access_key='YOUR_SECRET_ACCESS_KEY',

                       region_name='YOUR_REGION_NAME')

Connecting to a Bucket

Establish a connection to an S3 bucket:

s3_bucketclient = s3_conn.connect(bucket_name='your-bucket-name')

returns an S3 client instance.

Returns the current S3 client instance

s3_bucketclient = s3_conn.get_instance()

returns an S3 client instance.

Creating a bucket

Creates an S3 bucket with the provided name.

s3_client = s3_conn.connect()

s3_bucketclient = s3_conn.create_s3bucket(bucket_name='new-bucket-name')

Set Bucket CORS

Set the CORS configuration for the connected bucket

s3_conn.set_bucket_cors()



# CORSRules: A list of dictionaries containing CORS rules.

# If None, a default CORS rule allowing all origins and methods is applied.

cors_rules = [

    {

        'AllowedHeaders': ['*'],

        'AllowedMethods': ['GET', 'POST'],

        'AllowedOrigins': ['*'],

        'ExposeHeaders': [],

        'MaxAgeSeconds': 3000

    }

]



s3_conn.set_bucket_cors(CORSRules=cors_rules)

Get Bucket CORS

Retrieve the CORS configuration for the connected bucket

cors_config = s3_conn.get_bucket_cors()

Delete Bucket CORS

Delete the CORS configuration from the connected bucket

s3_conn.delete_bucket_cors()

Set Bucket Policy

Set or update the bucket policy for the connected bucket

s3_conn.set_bucket_policy()



# A JSON string or dictionary representing the bucket policy. 

# If None, a default public read policy is applied.



policy = {

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "PublicReadGetObject",

            "Effect": "Allow",

            "Principal": "*",

            "Action": "s3:GetObject",

            "Resource": f"arn:aws:s3:::{bucket_name}/*"

        }

    ]

}

s3_conn.set_bucket_policy(bucket_policy=policy)

Delete Bucket Policy

Delete the bucket policy from the connected bucket

s3_conn.delete_bucket_policy()

List User Policies

List inline policies for an IAM user

policies = s3_conn.list_user_policies(UserName='user-name')

Block or Allow Public Access

Block or allow public access to the bucket

s3_conn.public_access(block=True)  # Block public access

s3_conn.public_access(block=False) # Allow public access

Generate Presigned Create URL

Generate a presigned URL for creating an object

responce = s3_conn.presigned_create_url(

    object_name='my-object',

    params={'key': 'value'},

    fields={'field': 'value'},

    conditions=[{'condition': 'value'}],

    expiration=3600

)

object_name : The name of the object to be created in the S3 bucket.

params: (Optional) Additional request parameters to include in the presigned URL.

fields : (Optional) Pre-filled form fields to include in the presigned URL.

conditions: (Optional) Conditions to include in the presigned URL.

expiration : (Optional) Time in seconds for which the presigned URL should remain valid. Default is 3600 seconds (1 hour).

Generate Presigned Get URL

Generate a presigned URL for accessing an object

responce = s3_conn.presigned_get_url(object_name='my-object', expiration=3600)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudspark-1.0.9.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudspark-1.0.9-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file cloudspark-1.0.9.tar.gz.

File metadata

  • Download URL: cloudspark-1.0.9.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for cloudspark-1.0.9.tar.gz
Algorithm Hash digest
SHA256 6d6f2b40a1f58758206b6f42f7adabe53a6ab2d01b3be4f90aa4c4b14047d1b0
MD5 31a1aa2f3a031572c318ce022b300659
BLAKE2b-256 fd44562746f41accf7137b26b6f1acdbf798923f361e5b872d0d808c993e0a0a

See more details on using hashes here.

File details

Details for the file cloudspark-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: cloudspark-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for cloudspark-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6a9aac6e0a4ad11635d1d3fdbf71360a139652419ef67ccb758c2e4911c93245
MD5 09ced82832dc24b5b14bb066fbd0d344
BLAKE2b-256 682fb2348e34e6fadefbdda7e047ce75a5b48d4e76ac46556b8dbfd42f934d8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page