我遇到了一个问题,我试图使用适用于AWS S3的.net C#SDK来简单列出存储桶,但是我始终会遇到“访问被拒绝”异常。我在Windows 10上工作。
错误消息是:Amazon.S3.AmazonS3Exception: 'Access Denied'
我的C#代码是:
namespace AwsEmptyApp1
{
class Program
{
public static void Main(string[] args)
{
IAmazonS3 client = new AmazonS3Client();
ListBucketsResponse response = client.ListBuckets();
foreach (S3Bucket b in response.Buckets)
{
Console.WriteLine("{0}\t{1}", b.BucketName, b.CreationDate);
}
Console.Read();
}
}
}
我尝试通过以下方式手动设置代理:
AmazonS3Config config = new AmazonS3Config();
config.RegionEndpoint = //ENDPOINT
config.ProxyHost = //Proxy http://USERNAME:PASSWORD@PROXYIP:PROXYPORT
或者:
AmazonS3Config config = new AmazonS3Config();
config.RegionEndpoint = //ENDPOINT
config.ProxyHost = //Proxy http://PROXYIP:PROXYPORT
config.ProxyPort = 8080;
config.ProxyCredentials = new NetworkCredential(user, pw);
奇怪的是它正在使用本地CLI。
aws s3api head-bucket --bucket [BUCKETNAME]
正在工作。
aws s3 ls [BUCKET]
运行正常。
我也可以在网络界面中看到所有数据。
我使用aws sts get-caller-identity
检查了我的角色,并使用aws configure list
检查了我的凭据,一切正常。
我正在代理工作。代理设置在用户和系统变量HTTP_PROXY
和HTTPS_PROXY
中以http://USERNAME:PASSWORD@PROXYIP:PROXYPORT
的格式设置。
我的AWS凭证存储在C:\Users\[User]\.aws\credentials
您对我有什么建议吗?
谢谢! :)
答案 0 :(得分:-1)
解决了:)
我有一个本地app.config
文件,在其中我必须声明凭据文件中要使用的配置文件以及使用的区域:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="AWSProfileName" value="name"/>
<add key="AWSRegion" value="region" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
然后,我在凭证文件中添加了role_arn=
并且可以正常工作(只是必须在NugGet中安装AWSSDK.SecurityToken
,因为它也丢失了)