<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nathaniel Agbenyenu</title>
    <description>The latest articles on DEV Community by Nathaniel Agbenyenu (@nathanielnat).</description>
    <link>https://dev.to/nathanielnat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F309986%2F4df14f1f-eb6e-4418-9c60-b6660f29a26d.jpg</url>
      <title>DEV Community: Nathaniel Agbenyenu</title>
      <link>https://dev.to/nathanielnat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nathanielnat"/>
    <language>en</language>
    <item>
      <title>Streamlining Your Data Transfer</title>
      <dc:creator>Nathaniel Agbenyenu</dc:creator>
      <pubDate>Wed, 05 Apr 2023 10:30:16 +0000</pubDate>
      <link>https://dev.to/nathanielnat/streamlining-your-data-transfer-1moa</link>
      <guid>https://dev.to/nathanielnat/streamlining-your-data-transfer-1moa</guid>
      <description>&lt;p&gt;Security threats have been one of the major challenges faced by many organisations and over the years, huge sums of monies have been lost as a result of one security threat or the other.&lt;/p&gt;

&lt;p&gt;According to this &lt;strong&gt;&lt;a href="https://www.forbes.com/sites/splunk/2022/03/01/the-top-security-threats-of-2022/?sh=39b90da02e5d"&gt;report by Forbes&lt;/a&gt;&lt;/strong&gt;, the top 10 security threats of 2022 include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Credential Reuse Attack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Insider Threat&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Man-in-the-Middle Attack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Phishing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ransomware&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Watering Hole Attack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spyware&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Social Engineering Attack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DDoS Attack&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cloud Crypto-mining&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The report indicates that these 10 are the most malicious of &lt;a href="https://www.splunk.com/en_us/form/top-50-security-threats.html"&gt;**Top 50 Security Threats&lt;/a&gt;** that must be taken note of.&lt;/p&gt;

&lt;p&gt;This post discusses a way of mitigating the third threat; &lt;strong&gt;&lt;em&gt;Man-in-the-Middle Attack&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Man-in-the-Middle&lt;/strong&gt; happens when an attacker places himself between two targets and relays messages for them. The communicating parties may think there is a secure and direct communication between them but the attacker eavesdrops and possibly changes the original data stream from the sender before delivering it to the receiver.&lt;/p&gt;

&lt;p&gt;The workflow in many organizations involve data transfer from one system to another over a network.&lt;br&gt;
Medical history, transactional information, receipts, bank statements, geographical coordinates etc. are few examples of many sensitive data shared across networks.&lt;/p&gt;

&lt;p&gt;When files are sent over the internet, the data traverses the public internet with a high risk of being intercepted and tempered with.&lt;br&gt;
&lt;em&gt;A Man-in-the-Middle Attack&lt;/em&gt; is likely occur if the transfer is not made over a secure network. The repercussions of this can be dire as lives, money, reputations, security of nations amongst other things may be at risk if these files end up in the wrong hands.&lt;/p&gt;

&lt;p&gt;In this session, we’ll explore how to &lt;strong&gt;Securely Transfer Files To And From AWS S3 Buckets By Utilizing VPC Endpoints.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;VPC endpoints are virtual devices that are horizontally scaled, redundant, and highly available components of the Amazon VPC. They enable communication between Amazon VPC instances and AWS services without imposing availability risks or bandwidth constraints on network traffic.&lt;/p&gt;

&lt;p&gt;They aid customers to connect privately to AWS by providing a secure, efficient and cost-effective way to access services from within your VPC. &lt;br&gt;
They ensure security by allowing access to AWS services without going through the internet.&lt;br&gt;
The network architecture is simplified since there is no need for a NAT Gateway. This makes it easy to setup and manage.&lt;/p&gt;

&lt;p&gt;Network performance is also improved with a reduction in network cost as well. The ability to provide direct access to AWS services reduces latency and improves overall performance of applications while reducing cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now let’s dive deep into the tutorial
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Prerequisites: You must have an AWS account.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This tutorial requires an AWS account and a secure connection established between the account and whatever instance required to reach it.&lt;/p&gt;

&lt;p&gt;VPC endpoints are created in specific VPCs and are accessible only to systems that have access to those VPCs. The requests may come from other AWS accounts or on-premise networks. Connectivity must be established between the networks in order to proceed.&lt;/p&gt;

&lt;p&gt;Connectivity with other AWS accounts require VPC Peering while connectivity with on-premise networks requires establishing a Site-to-Site VPN connection between the two networks.&lt;/p&gt;

&lt;p&gt;Ensure that a &lt;a href="https://docs.aws.amazon.com/vpn/latest/s2svpn/working-with-site-site.html"&gt;Site-to-Site VPN connection&lt;/a&gt; or a &lt;a href="https://docs.aws.amazon.com/vpc/latest/peering/create-vpc-peering-connection.html"&gt;VPC Peering connection&lt;/a&gt; is established depending on your use case.&lt;/p&gt;

&lt;p&gt;The S3 bucket to/from which the files would be accessed must also exit.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Login to your AWS account and in the search bar, type VPC, navigate to the VPC page and click on “Endpoints”&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BO2x8nf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2314/1%2AvNlJJZVOboP3TMpJTQ5idg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BO2x8nf0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2314/1%2AvNlJJZVOboP3TMpJTQ5idg.png" alt="Click on Endpoints on the VPC Page" width="880" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Click on “Create endpoint”.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_BWz5_mp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3762/1%2AbSbKJ5_ZJivEnLRiFVVECQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_BWz5_mp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3762/1%2AbSbKJ5_ZJivEnLRiFVVECQ.png" alt="Click on create endpoint" width="880" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Fill the details below.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WxUcxmoA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AFND2_x8KrxJpq5mC3danZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WxUcxmoA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AFND2_x8KrxJpq5mC3danZA.png" alt="" width="880" height="893"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Enter the name of the endpoint you want to create.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select the AWS services in the service category.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All the AWS services that are accessible via VPCEs are listed here. You can select as many services as you want but in our use case, we only need access to the S3 hence we select only that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the services, select the interface type of the S3 services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are two types of VPC endpoints; **Interface and Gateway **endpoints. We are going to work with interface endpoints because they support a host of services and are accessible via peered VPCs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Specify the VPC and subnets where the endpoint would be created.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pExfez2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AX6bUbxkDxN_ZxGw3pzWsQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pExfez2c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AX6bUbxkDxN_ZxGw3pzWsQA.png" alt="Specify the VPC, subnet and security group for the VPCE" width="880" height="834"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the VPC that as peered in &lt;em&gt;Step 1.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose the private subnets in that VPC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you want to limit access to only specific IP addresses in the other account, create a security group and grant access to IPs or range of IPs allowed to reach it on port 443 as well.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Edit the VPCE policy to limit access to specific services.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KUlbRDoA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Az2pQXhJQV7M6_lANITc4UA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KUlbRDoA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Az2pQXhJQV7M6_lANITc4UA.png" alt="" width="880" height="754"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Granting full access would give users or services in the source accounts the ability to access all AWS services in the destination account, which is not recommended. In order to implement the &lt;em&gt;Principle of Least Privilege&lt;/em&gt;, select custom to limit access to only the services they are required to reach and in this case the designated S3 bucket.&lt;/p&gt;

&lt;p&gt;Go ahead and create the endpoint. Next, we’ll modify the bucket’s policy to allow access from the VPCE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Modify the bucket’s ACL to allow access from the VCPE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--imHGCzS0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Aww0aUu9G9s6SgImxuZ_Tbw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--imHGCzS0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Aww0aUu9G9s6SgImxuZ_Tbw.png" alt="edit bucket acl" width="817" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessing Objects In The Bucket.
&lt;/h2&gt;

&lt;p&gt;Now that we have successfully created our VPCE, we would go ahead and use it to access our S3 bucket and perform various operations on the bucket. Objects in the bucket can be accessed by the AWS CLI or CDK.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using The AWS CLI
&lt;/h3&gt;

&lt;p&gt;Below are the steps to follow when connecting with AWS CLI:&lt;br&gt;
First, ensure the &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd"&gt;AWS CLI&lt;/a&gt; is installed on the device trying to reach the bucket.&lt;/p&gt;

&lt;p&gt;In the examples below, replace the VPC endpoint ID&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;“vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com”&lt;/em&gt;&lt;/strong&gt;, filename “&lt;strong&gt;&lt;em&gt;file.txt”&lt;/em&gt;&lt;/strong&gt;, the region and bucket name “&lt;strong&gt;&lt;em&gt;my-bucket”&lt;/em&gt;&lt;/strong&gt; with appropriate information.&lt;/p&gt;

&lt;p&gt;In the details tab of the VPCE created, copy the DNS name. There are usually 4 DNS names for every VPCE. The first one indicates the endpoint at the regional level whiles the others are at the availability zone level.&lt;/p&gt;

&lt;p&gt;Copy he first one to proceed.&lt;/p&gt;

&lt;p&gt;Let’s say our file of interest here is file.txt&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List Files In Bucket&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 --region eu-west-1 \
--endpoint-url https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com \
ls s3://my-bucket/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Write File To Bucket&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 --region eu-west-1 \ 
--endpoint-url https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com \ 
cp file.txt s3://my-bucket/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For instance, if there is file on the host called, file.txt. the command above is used to copy it to the bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download File From Bucket&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 --region eu-west-1 \
--endpoint-url https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com  \
cp s3://my-bucket/file.txt file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To download a file “file.txt” to the host, use the command above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using The AWS SDK
&lt;/h3&gt;

&lt;p&gt;Various AWS clients can be employed to access S3 buckets with various programming languages. The clients have to be configured to use an endpoint URL for accessing buckets and performing operations through S3 interface endpoints. Here are some examples of such configurations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using The AWS Python SDK (Boto3)&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s3_client = session.client(
service_name='s3',
region_name='eu-west-1',
endpoint_url='https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com'
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Using The AWS SDK For Java 1.x&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bucket client
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withEndpointConfiguration(
        new AwsClientBuilder.EndpointConfiguration(
                "https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com",
    Regions.DEFAULT_REGION.getName()
        )
).build();
List&amp;lt;Bucket&amp;gt; buckets = s3.listBuckets();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Using The AWS SDK For Java 2.x&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bucket client
Region region = Region.EU_WEST_1;
s3Client = S3Client.builder().region(region).endpointOverride(
URI.create("https://bucket.vpce-1a2b3c4d-5e6f.s3.eu-west-1.vpce.amazonaws.com")
).build()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Refer to the official &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/privatelink-interface-endpoints.html#accessing-bucket-and-aps-from-interface-endpoints"&gt;AWS documentation&lt;/a&gt; for further details.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;References:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://www.enisa.europa.eu/topics/incident-response/glossary/man-in-the-middle"&gt;https://www.enisa.europa.eu/topics/incident-response/glossary/man-in-the-middle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo Credit : &lt;a href="https://www.pexels.com/@seanpatrickphotography/"&gt;Sean Patrick on Pexels&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>cloud</category>
      <category>security</category>
    </item>
    <item>
      <title>Get Sizes of All S3 Buckets In AWS SSO Accounts With Python</title>
      <dc:creator>Nathaniel Agbenyenu</dc:creator>
      <pubDate>Fri, 10 Mar 2023 09:13:11 +0000</pubDate>
      <link>https://dev.to/nathanielnat/get-sizes-of-all-buckets-in-aws-sso-accounts-with-python-3731</link>
      <guid>https://dev.to/nathanielnat/get-sizes-of-all-buckets-in-aws-sso-accounts-with-python-3731</guid>
      <description>&lt;p&gt;Let's say you've been tasked to produce an excel document containing the sizes of all the s3 buckets in multiple AWS accounts. This is a tedious task and would take a lot of time.&lt;br&gt;
I was in a similar situation but then I came up with a simple python script to do that. &lt;/p&gt;

&lt;p&gt;All the accounts were on SSO so it was simpler to achieve this having already &lt;a href="https://towardsthecloud.com/set-up-aws-cli-aws-sso"&gt;configured SSO&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This tutorial assumes that you have set up AWS SSO and have the necessary permissions to access the S3 buckets in the specified account. You may also need to install the boto3 library if it is not already installed on your system.&lt;/p&gt;
&lt;h4&gt;
  
  
  Initializing the boto3 client
&lt;/h4&gt;

&lt;p&gt;The boto3 client is initialized first. A session is created for the SSO profile. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wzqS6c-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hks65w19ugb6k3mjl0sc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wzqS6c-M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hks65w19ugb6k3mjl0sc.png" alt="Image description" width="880" height="552"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Getting the list of all buckets in the account
&lt;/h4&gt;

&lt;p&gt;Next, the list of all the buckets in the account are retrieved.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PrPpd_At--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9464t8se8uzq28f0r8z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PrPpd_At--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y9464t8se8uzq28f0r8z.png" alt="Image description" width="880" height="509"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Calculating the size of objects in each bucket
&lt;/h4&gt;

&lt;p&gt;For each of the buckets listed above, the size of the objects in the bucket(GB) are calculated. The code reads the contents of the objects and calculates the size of each. A key error is raised for buckets that are empty since  there are no contents.&lt;br&gt;
A dictionary of the buckets and their sizes is then created and returned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OAynMgZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl7o2qa1fgj2d68lbgst.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OAynMgZj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl7o2qa1fgj2d68lbgst.png" alt="Image description" width="880" height="507"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Write to csv
&lt;/h4&gt;

&lt;p&gt;A csv file named after the sso profile is then generated with the columns being the bucket name and the object size.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QXLgehog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn5ms7ln4orneephq9l7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QXLgehog--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn5ms7ln4orneephq9l7.png" alt="Image description" width="880" height="577"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Bringing it all together
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4SyPBZYw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7x2t5f5qjcxmeh2tn6kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4SyPBZYw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7x2t5f5qjcxmeh2tn6kv.png" alt="Image description" width="880" height="1660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To run this code you need to pass the sso profile as an argument. &lt;br&gt;
For example if your code file is s3_size.py and the sso profile is production, you execute it by entering the following command in the terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python s3_size.py production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>aws</category>
      <category>python</category>
      <category>devops</category>
      <category>s3</category>
    </item>
  </channel>
</rss>
