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?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南