简体   繁体   English

如何使用在端口443上部署的API尝试读取S3对象来修复AWS S3上的访问被拒绝的问题

[英]How to fix access denied issue on aws S3 with API deployed on port 443 trying to read the s3 objects

I have a Restful API (asp .net 4.5.2) deployed on EC2 instance and EC2 instance is having IAM role for accessing S3 bucket (full access to bucket). 我在EC2实例上部署了一个Restful API(asp .net 4.5.2),并且EC2实例具有IAM角色,用于访问S3存储桶(对存储桶的完全访问)。 Now when I am trying to read the objects in bucket, it is returning Access Denied (403) in response and when I am trying to upload any attachment via pre-signed url, it is returning AWS signature mismatch in response when my API is deployed on port 443 but it is working fine when API is deployed on any other port like 80/81 and bucket is accessible through aws-cli. 现在,当我尝试读取存储桶中的对象时,它会返回Access Denied(403)作为响应,而当我尝试通过预签名的URL上传任何附件时,它会在部署我的API时返回AWS签名不匹配在端口443上,但是当API部署在任何其他端口(例如80/81)上并且可以通过aws-cli访问bucket时,它工作正常。 Any idea why it might be happening? 知道为什么会发生吗?

my code snippets for reading objects: 我的用于读取对象的代码段:

using (var s3Client = new AmazonS3Client(bucketRegion))
{
ListObjectsV2Request request = new ListObjectsV2Request
{
BucketName = bucketName,
MaxKeys = 10
};
ListObjectsV2Response response;

response = s3Client.ListObjectsV2Async(request).Result;
            // Process the response.
            foreach (S3Object entry in response.S3Objects)
            {
                keyValuePairs.Add(entry.Key, entry.Size);
            }

}

I need to pass the InstanceProfileAWSCredentials profile while instantiating s3Client object and it solved my problem. 我需要在实例化s3Client对象时传递InstanceProfileAWSCredentials配置文件,它解决了我的问题。

var profile = new InstanceProfileAWSCredentials();
using (var s3Client = new AmazonS3Client(profile, bucketRegion))
{
ListObjectsV2Request request = new ListObjectsV2Request
{
BucketName = bucketName,
MaxKeys = 10
};
ListObjectsV2Response response;

response = s3Client.ListObjectsV2Async(request).Result;
        // Process the response.
        foreach (S3Object entry in response.S3Objects)
        {
            keyValuePairs.Add(entry.Key, entry.Size);
        }

}

This could be an issue related to your security group on EC2 instances. 这可能是与您的EC2实例上的安全组有关的问题。 you have to open port 443 (HTTPS). 您必须打开端口443(HTTPS)。 if this does not work the issue is related to port being in use by another application. 如果这不起作用,则问题与另一个应用程序正在使用的端口有关。 check all your services that uses port 443. 检查所有使用端口443的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM