Tech Blog

Cloud Computing

Listing S3 Buckets using ASP .NET Core Part-2

By 42Gears Team2 min read
← Back to blog

As we have already seen in the previous blog “Various operations on S3 Bucket using .NET core” all the prerequisites required to get started with Listing of S3 Buckets using ASP .NET Core.

In AWS S3 Bucket all the files and folders are treated as objects.

Let’s try to retrieve the Bucket names that are present in our S3 bucket, I am listing one bucket that is present in my S3 bucket called “rashmi-test” and gets its creation date.

public static async Task ListBuckets()
        {
            AmazonS3Client Client = new AmazonS3Client(PublicKey, SecretKey, Region);

            ListBucketsResponse listBucketsResponse = await Client.ListBucketsAsync();

            List<S3Bucket> S3Buckets = listBucketsResponse.Buckets;

            foreach (S3Bucket s3Bucket in S3Buckets)
            {
                Console.WriteLine(" Bucket Name is :" + s3Bucket.BucketName + " Creation Date is :" + s3Bucket.CreationDate);
            }

        }

We are initializing the AmazonS3Client and passing the PublicKey, SecretKey, and Region, the values for these are accessed from appsetting.json that we have seen in the previous blog. In the next step, we are creating a list of Bucket using the function ListBucketsAsync(). Then we are using a loop to access all the buckets. Below is the output attached which shows the Bucket name. If you have multiple buckets all of them will be there in the output window.

This is how we List Amazon S3 buckets using ASP .NET Core. In the next blog we will see how to List Items in a bucket using ASP .NET Core.

Keep reading

You may be interested in

Browse all articles →
How to Configure AWS CLI?
December 30, 20224 min read

How to Configure AWS CLI?

In Cloud platforms such as AWS, GCP, and Azure we have multiple ways to access cloud services and our resources like GUI (Console), CDK, and CLI. In today’s blog, we are going to look at CLI access in AWS. Like all other cloud providers, AWS also provides CLI access to their services for that first […]

By Keerthik ShenoyRead More →
AWS Automation with Python Boto3
December 30, 20223 min read

AWS Automation with Python Boto3

Automation plays a major role in In Cloud and DevOps, we have many tools to automate manual processes like Infrastructure automation with Terraform, for CICD Jenkins, GitLab, AWS, code pipeline, etc. In the same way, we can automate some of the AWS tasks with a simple python script using the oto3 library. Let’s see some […]

By Keerthik ShenoyRead More →
AWS Cost Optimization Techniques
December 15, 20224 min read

AWS Cost Optimization Techniques

AWS is the world’s leading cloud computing platform, providing a wide range of services including computer computing, storage, networking, and platform as a service (PaaS). AWS cost optimization requires identifying areas for cost-saving measures, tracking your usage, and putting advice into practice. Your Amazon costs are largely influenced by the cost of EC2 instances provided […]

By Keerthik ShenoyRead More →