snippets_py
Integration
New integration from credential
aws_s3_client = yepcode.integration.aws_s3("credential-slug")
New integration from plain authentication data
import boto3
session = boto3.Session(
aws_access_key_id="accessKeyId",
aws_secret_access_key="secretAccessKey",
region_name="region"
)
aws_s3_client = session.client("s3")
List Buckets
List buckets
response = aws_s3_client.list_buckets()
for bucket in response['Buckets']:
print(bucket)
Create a Bucket
Create a bucket
aws_s3_client.create_bucket(Bucket="bucket-name")
Delete a Bucket
Delete a bucket
aws_s3_client.delete_bucket(Bucket="bucket-name")
Get File Content
Get file content
response = aws_s3_client.get_object(
Bucket="bucket_name", Key="object_key"
)
file_stream = response['Body']
print(file_stream.read().decode('utf-8'))
Upload File
Upload file
aws_s3_client.put_object(
Bucket="bucket_name", Key="object_key", Body="object_body"
)
Upload File with Stream
Upload file with stream
import io
sample_file_content = """
Sample file content
With 2 lines
"""
content_stream = io.BytesIO()
content_stream.write(sample_file_content.encode('utf-8'))
# Reset stream position to the beginning
content_stream.seek(0)
aws_s3_client.put_object(
Bucket="bucket_name", Key="object_key", Body=content_stream
)