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?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ