S3 is storage provided by AWS. It stores data inside buckets.
We can upload data to s3 using boto3 library. Here is code which also works for AWS lambda functions.
Below is sample code to upload files to S3 using python :
import json
import boto3
import requests
access_key='your_access_key'
secret_access='your_secret_access'
region = 'your_region'
s3 = boto3.resource('s3', region_name=region, aws_access_key_id=access_key,
aws_secret_access_key=secret_access)
def s3_uplaod(bucket, domain,content):
file_path = '{}/{}'.format(domain,"name_of_file")
object = s3.Object(bucket, file_path)
object.put(Body=content)
def main(job):
try:
bucket = 'your_bucket_name'
domain = 'sub-folder_inside_bucket'
content = 'local_location_of_file'
s3_uplaod(bucket, domain,content)
except Exception as e:
print(e)
def handler(event, context):
main(event)
handler('a','a')
Notes:
We can upload data to s3 using boto3 library. Here is code which also works for AWS lambda functions.
Below is sample code to upload files to S3 using python :
import json
import boto3
import requests
access_key='your_access_key'
secret_access='your_secret_access'
region = 'your_region'
s3 = boto3.resource('s3', region_name=region, aws_access_key_id=access_key,
aws_secret_access_key=secret_access)
def s3_uplaod(bucket, domain,content):
file_path = '{}/{}'.format(domain,"name_of_file")
object = s3.Object(bucket, file_path)
object.put(Body=content)
def main(job):
try:
bucket = 'your_bucket_name'
domain = 'sub-folder_inside_bucket'
content = 'local_location_of_file'
s3_uplaod(bucket, domain,content)
except Exception as e:
print(e)
def handler(event, context):
main(event)
handler('a','a')
Notes:
- You can replace required parameters like keys and bucket name.
- domain : used where we have folder inside bucket.
- if path doesn't exist inside bucket it will create required path.
- You can skip handler part if not using code for AWS lambda functions.
You can comment below if you face any issues here.
It was extremely helpful to understand the basic conflict management options. Applying these to a specific issue that I am dealing with helped me get past a big hurdle. Thank you!DevOps Training in Chennai
ReplyDeleteDevOps Online Training in Chennai
DevOps Training in Bangalore
DevOps Training in Hyderabad
DevOps Training in Coimbatore
DevOps Training
DevOps Online Training
Excellent Blog! I would Thanks for sharing this wonderful content.its very useful to us.I gained many unknown information, the way you have clearly explained is really fantastic.
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course
Full Stack Training in Bangalore | Certification | Online Training Course
Full Stack Training in Hyderabad | Certification | Online Training Course
Full Stack Developer Training in Chennai | Mean Stack Developer Training in Chennai
Full Stack Training
Full Stack Online Training
This article was exactly what I needed to read today.
ReplyDeletealso, check Python training in Nagpur
Thanks for sharing article with us .
ReplyDeletePython Training in Solapur
great post , learn things from your blog thanks for this information. Are you intresting in code developer then checkout python training in satara
ReplyDelete