{"id":5870,"date":"2022-06-30T04:55:08","date_gmt":"2022-06-30T04:55:08","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=5870"},"modified":"2022-06-30T05:34:15","modified_gmt":"2022-06-30T05:34:15","slug":"brief-guide-to-s3-bucket-in-python","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/","title":{"rendered":"Brief guide to S3 bucket in python"},"content":{"rendered":"<p>In this post, we will discuss some basic operations performed on S3 buckets in python. In this discussion, we will consider that you have some basic knowledge of AWS and the S3 bucket. Firstly before we start we need to understand that we need some packages required, to perform the below operations.<\/p>\n<h2>Install the Boto3:<\/h2>\n<p>Boto3 is the Amazon Web Services Software Development Kit, which allows Python developers to write software that makes use of services like Amazon S3.<br \/>\n<code>pip install boto3<\/code><\/p>\n<h3>How to Upload Files in S3 bucket in python?<\/h3>\n<p>In this section, you\u2019ll learn how to read a file from a local system and update it to an S3 object.<br \/>\n<code>def UploadFilesOnBucket(bucketName, folderName, srcLocation):<br \/>\n\ttry:<br \/>\n    \tkeyName = folderName +os.sep+ os.path.basename(srcLocation)<br \/>\n    \tprint(keyName + \"\\nUploaded\\n\")<br \/>\n    \tS3_BUCKET.Bucket(bucketName).upload_file(Filename=srcLocation, Key=keyName)<br \/>\n\texcept Exception as e:<br \/>\n    \tprint(e)<\/code><\/p>\n<p>upload_file is a predefined function which requires 2 parameters: firstly the source location of the file from where the file is placed and the second parameter is the location of the destination.<\/p>\n<h3>How to Delete Files in S3 bucket in python?<\/h3>\n<p>In this section, you\u2019ll learn how to delete a file from an S3 object.<br \/>\n<code>def deleteFromS3bucket(<br \/>\n\tsessionObj, bucketName, fileDeleteOnS3Bucket, destinationPathForS3Bucket):<br \/>\n\ttry:<br \/>\n    \ts3Obj = sessionObj.resource(\"s3\")<br \/>\n    \tyour_bucket = s3Obj.Bucket(bucketName)<br \/>\n    \ts3 = sessionObj.resource(\"s3\")<br \/>\n    \tobj = s3.Object(bucketName, fileDeleteOnS3Bucket)<br \/>\n    \tobj.delete()<br \/>\n\texcept Exception as e:<br \/>\n    \tprint(e)<\/code><\/p>\n<p>obj.delete() is a predefined function which requires 2 parameters: firstly the bucket name and the second parameter is the location of the file.<br \/>\nHow to get all files from the S3 bucket in python?<\/p>\n<p>In this section, you\u2019ll learn how to get listing all the files from an S3 object.<br \/>\n<code>def getFilesListing(sessionObj,bucketName):<br \/>\n\ttry:<br \/>\n    \ts3Obj = sessionObj.resource('s3')<br \/>\n    \tyour_bucket = s3Obj.Bucket(bucketName)<br \/>\n    \ti=1<br \/>\n    \tfor s3_file in your_bucket.objects.all():<br \/>\n        \tprint(s3_file.key)<br \/>\n        \ti=i+1<br \/>\n\texcept Exception as e:<br \/>\n    \tprint(e)<\/code><br \/>\ns3Obj.Bucket() is a predefined function which requires the name of the bucket after which we iterate over the array to print the listing of the FIle as shown above.<\/p>\n<p><small>English is a commonly used language in almost all fields today. Having a certification in the English language can enhance your career aspects. StudySection offers both basic level and advanced level <a href=\"https:\/\/www.studysection.com\/english-language-foundation\">English certification<\/a> exams to test and certify the English language skills.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will discuss some basic operations performed on S3 buckets in python. In this discussion, we will<\/p>\n","protected":false},"author":1,"featured_media":5871,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[33,790],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Brief guide to S3 bucket in Python-SS Blog<\/title>\n<meta name=\"description\" content=\"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Brief guide to S3 bucket in Python-SS Blog\" \/>\n<meta property=\"og:description\" content=\"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-30T04:55:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-30T05:34:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/06\/S3-bucket.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Brief guide to S3 bucket in python\",\"datePublished\":\"2022-06-30T04:55:08+00:00\",\"dateModified\":\"2022-06-30T05:34:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\"},\"wordCount\":297,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Python\",\"S3 bucket\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\",\"url\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\",\"name\":\"Brief guide to S3 bucket in Python-SS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2022-06-30T04:55:08+00:00\",\"dateModified\":\"2022-06-30T05:34:15+00:00\",\"description\":\"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Brief guide to S3 bucket in python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Brief guide to S3 bucket in Python-SS Blog","description":"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Brief guide to S3 bucket in Python-SS Blog","og_description":"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.","og_url":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2022-06-30T04:55:08+00:00","article_modified_time":"2022-06-30T05:34:15+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/06\/S3-bucket.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Brief guide to S3 bucket in python","datePublished":"2022-06-30T04:55:08+00:00","dateModified":"2022-06-30T05:34:15+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/"},"wordCount":297,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Python","S3 bucket"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/","url":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/","name":"Brief guide to S3 bucket in Python-SS Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2022-06-30T04:55:08+00:00","dateModified":"2022-06-30T05:34:15+00:00","description":"We will discuss some basic operations performed on S3 buckets in Python. We will consider that you have knowledge of AWS and the S3 bucket.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/brief-guide-to-s3-bucket-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Brief guide to S3 bucket in python"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":177,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5870"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=5870"}],"version-history":[{"count":1,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5870\/revisions"}],"predecessor-version":[{"id":5872,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5870\/revisions\/5872"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/5871"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=5870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=5870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=5870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}