VPC内のEC2などから、S3へのアクセスは、インターネット経由になりますが、
S3のGateway型VPCエンドポイントを作成しますと、インターネット経由ではなく、プライベートサブネット内からアクスセスできるようになります。

| サービス | S3(com.amazonaws.ap-northeast-1.s3)Gateway |
| VPC | エンドポイントを作成するVPCを選択 |
| Route tables | S3エンドポイントのルーティングを追加するルートテーブルを撰択。 |
| Policy | Full access |
Gateway型のS3 VPC Endpoint経由でアクセスする場合「--region リージョン」指定が必要です。
aws s3 ls --region ap-northeast-1 s3://<バケット名>/
VPC エンドポイントからのみに制限する Amazon S3 のバケットポリシー
{
"Id": "VPCe",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VPCe",
"Action": "s3:*",
"Effect": "Deny",
"Resource": [
"arn:aws:s3:::<<S3-BUCKET-NAME>>",
"arn:aws:s3:::<<S3-BUCKET-NAME>>/*"
],
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": [
"<<VPC-ENDPOINT-ID>>"
]
}
},
"Principal": "*"
}
]
}
{
"Id": "VPCe",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VPCe",
"Effect": "Deny",
"Resource": [
"arn:aws:s3:::<<S3-BUCKET-NAME>>",
"arn:aws:s3:::<<S3-BUCKET-NAME>>/*"
],
"NotAction": [
"s3:ListBucket",
"s3:ListAllMyBuckets"
],
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": [
"<<MY-ENDPOINT-ID>>"
]
}
},
"Principal": "*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "*",
"Resource": [
"arn:aws:s3:::Bucket-AAAA/*",
"arn:aws:s3:::Bucket-AAAA"
]
}
]
}
https://yohei-a.hatenablog.jp/entry/20201222/1608602963
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"s3:ResourceAccount": [
"012345678901",
"123456789012"
]
}
}
}
]
}
インターネットにアクセスせずに自分の AL1 または AL2 EC2 インスタンスで yum を更新する
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"s3:ResourceAccount": [
"012345678901",
"123456789012"
]
}
}
},
{
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::amazonlinux.*.amazonaws.com/*",
"arn:aws:s3:::amazonlinux-2-repos-*/*"
]
}
]
}
以下のみに限定する設定
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": [
"vpce-xxxxxxx"
]
},
"NotIpAddress": {
"aws:SourceIp": [
"x.x.x.x/32"
]
},
"Bool": {
"aws:ViaAWSService": "false"
}
}
}
}
Amazon S3は、容量無制限の安価なオブジェクトストレージ
一般向けサイト
ITエンジニア向けサイト
英語サイト
Portfolio
Copyright (c) 2025 クラウドのインフラ技術 All Rights Reserved.