LoginSignup
0
0

【aws】クロスアカウントでのS3取得

Last updated at Posted at 2023-08-28

実現したいこと

  • account1にあるLambdaからaccount2にあるS3内のファイルを取得する
  • S3の取得には何かしらの制限をかける必要がある
    スクリーンショット 2023-08-28 17.59.55.png

[NG] LambdaのIPを固定してS3にIP制限をかける

AWS構成

スクリーンショット 2023-08-28 18.03.42.png

  • LambdaのIPを固定

  • S3にIP制限をかける
    • ブロックパブリックアクセス:オフ
    • バケットポリシー:以下の通り
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::{バケット名}/*",
            "Condition": {
                "IpAddress": {
                    "aws:SourceIp": {NAT Gatewayの固定IP}
                }
            }
        }
    ]
}

結果

ファイル取得できず。
S3から 403 Forbidden が返ってきていました。

試しにS3のIP制限をなくしたところ、画像が取得できたため、取得元のIPが間違っていると推測。
NAT Gatewayを経由していないようです。

VPCエンドポイント経由で取得していた

AWS構成

スクリーンショット 2023-08-28 20.59.29.png

  • S3のバケットポリシーでVPCエンドポイントIDを指定すると、無事ファイルが取得できました。
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::{バケット名}/*",
            "Condition": {
                "StringEquals": {
                    "aws:SourceVpce": {VPCエンドポイントID(s3)}
                }
            }
        }
    ]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0