Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWS.NET SDK:不使用access/Secret密钥创建AmazonS3Client?_.net_Amazon Web Services_Amazon S3_Sdk - Fatal编程技术网

AWS.NET SDK:不使用access/Secret密钥创建AmazonS3Client?

AWS.NET SDK:不使用access/Secret密钥创建AmazonS3Client?,.net,amazon-web-services,amazon-s3,sdk,.net,Amazon Web Services,Amazon S3,Sdk,我知道如何使用访问/保密密钥访问S3: string accessKey = "my access key"; string secretKey = "my secrete key"; IAmazonS3 client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.APSoutheast2); ListBucketsResponse response = client.ListBuckets(); 但是,这意味着将密钥存

我知道如何使用访问/保密密钥访问S3:

string accessKey = "my access key"; 
string secretKey = "my secrete key"; 
IAmazonS3 client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.APSoutheast2);
ListBucketsResponse response = client.ListBuckets();
但是,这意味着将密钥存储在代码中。此代码在EC2实例上运行,我已为其分配了S3完全管理IAM角色。我可以打开一个CMD窗口并输入“aws s3 ls”它就工作了。但如果我将NULL传递给上述代码中的两个键,它将抛出以下错误:

Invalid S3 URI - hostname does not appear to be a valid S3 endpoint

那么,如何在已分配了S3 full adminIAM角色的EC2实例上运行上述代码,而无需硬编码访问密钥?

请参见下面一半的示例-


您将看到您没有将任何内容传递给构造函数。

请看下面一半的示例-


您将看到您没有向构造函数传递任何内容。

使用不以accessKey和secret作为参数的构造函数:

IAmazonS3 client = new AmazonS3Client(RegionEndpoint.APSoutheast2);
ListBucketsResponse response = client.ListBuckets();

通过完全省略它们,SDK将为它们访问角色。

使用不以accessKey和secret作为参数的构造函数:

IAmazonS3 client = new AmazonS3Client(RegionEndpoint.APSoutheast2);
ListBucketsResponse response = client.ListBuckets();
通过完全省略它们,SDK将为它们访问角色