Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (5.6k points)
The AWS Cloud Map says, that it works with S3 buckets. I'm struggling to understand how can I set up the AWS S3 SDK to use cloud map namespaces and the services when making the request to the S3 bucket. Is there any way that covers setting up an S3 bucket, adding it to the cloud map, and using the AWS S3 SDK to access the S3 bucket using the cloud map?

1 Answer

0 votes
by (12.4k points)

You need to use the "AWSSDK.ServiceDiscovery NuGet" package to resolve the service from your Cloud Map namespaces. Once you resolve the service you use that value with the S3 service client. 

Providing the sample code,

using System;

using System.Collections.Generic;

using System.Threading.Tasks;

using Amazon;

using Amazon.S3;

using Amazon.S3.Model;

using Amazon.ServiceDiscovery;

using Amazon.ServiceDiscovery.Model;

namespace ServiceDiscoveryTest

{

    class Program

    {

        static async Task Main(string[] args)

        {

            using(var discoveryClient = new AmazonServiceDiscoveryClient(RegionEndpoint.USEast1))

            using(var s3Client = new AmazonS3Client(RegionEndpoint.USEast1))

            {

                var discoveryResponse = await discoveryClient.DiscoverInstancesAsync(new DiscoverInstancesRequest

                {

                    NamespaceName = "dev",

                    ServiceName = "mystorage",

                    QueryParameters = new Dictionary<string, string> 

                    { 

                        { "Version", "1.0" } 

                    }

                });

                var listResponse = await s3Client.ListObjectsAsync(new ListObjectsRequest

                {

                    BucketName = discoveryResponse.Instances[0].InstanceId

                });

                foreach(var s3Object in listResponse.S3Objects)

                {

                    Console.WriteLine(s3Object.Key);

                }

            }

        }

    }

}

Hope this helps!!

Do you want to master AWS? Then do check out the AWS Certified Solutions Architect Professional certification by Intellipaat!

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...