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.
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);
}
}
}
}
}