How to add bucket policy to allow http API gateway routes to access S3 bucket data using S3 URL

0

Hi, I am experimenting the possibility to authenticate S3 file download using S3 URL, right now, I used HTTP Gateway that has a HTTP Integration that GET the S3 Object using S3 URL. Currently the bucket blocks all public access, I would be wondering if that's possible to write a bucket policy to allow API Gateway to access the object using the object URL from that integration. I tried this policy statement, but it seems it doesn't work, and I still got access denied

{
            "Sid": "AllowAccessFromAPIGateway",
            "Effect": "Allow",
            "Principal": {
                "Service": "apigateway.amazonaws.com"
            },
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::my-bucket/*",
            "Condition": {
                "ArnLike": {
                    "aws:SourceArn": "arn:aws:execute-api:us-east-1:account-id:api-id/$default/GET/image"
                }
            }
        }
1개 답변
0

APi gateway runs as an IAM role. You need to grant access to the role and not the service.

This example seems to be aligned with what you seem to be trying to achieve and help guide you with the permissions needed.

https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html

profile picture
전문가
답변함 10달 전
  • Thank you for the reply! I actually experimented this already. The limit is that the file size limit is 10 MB, so I would really like a way that only authenticate the URL call but does not have this size limit. That's why I am working this way around. Also, from my experiment, I notice, if I want to access object that is within the sub folder: bucket/sub/item.bin, I couldn't get it by filling {bucket} to bucket and {item} to sub/item.bin`, it will list all the bucket instead. Do you have any idea on this?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인