Professional Documents
Culture Documents
TOPICS COVERED:
EC2 Instance:
S3 Bucket:
S3 CONFIGURATION:
LAMBDA
CLOUDWATCH:
JSON:
BOTO3:
● The AWS SDK for Python provides a pair of methods to upload a file to an S3
bucket.
● The upload_file method accepts a file name, a bucket name, and an object
name. The method handles large files by splitting them into smaller chunks and
uploading each chunk in parallel.
Example: s3 = boto3.client('s3')
with open("FILE_NAME", "rb") as f:
s3.upload_fileobj(f, "BUCKET_NAME", "OBJECT_NAME")
FILE HANDLING:
● Python has several functions for creating, reading, updating, and deleting files.
● The open() function takes two parameters; filename, and mode.
SYNTAX:
"r" - Read - Default value. Opens a file for reading, error if the file does not exist
Eg:
file = open(“filename.txt”)
file = open(“filename.txt”, “r”)
print(file.read())
"a" - Append - Opens a file for appending, creates the file if it does not exist
Eg:
file = open(“filename.txt”, “a”)
file.write(“HELLO”)
File.close
"w" - Write - Opens a file for writing, creates the file if it does not exist
Eg:
file = open(“filename.txt”, “w”)
file.write(“HELLO”)
File.close
Delete a file:
To delete a file, you must import the OS module, and run its os.remove() function
Eg:
import os
os.remove("filename.txt")
Eg:
Import boto3
s3 = boto3.client('s3')
s3.upload_file(“Filename.txt”, “Bucketname”, “bucket file name”)