1 Answer
- Newest
- Most votes
- Most comments
0
Hello.
It is possible to restrict the source of uploads to an S3 bucket by implementing IP restrictions as shown below.
CodeBuild can connect to a VPC, so you can access S3 using a NAT Gateway or a VPC endpoint.
In other words, by restricting the source of connections using bucket policy, you can prevent uploads from outside even if a signed URL is misused.
https://docs.aws.amazon.com/codebuild/latest/userguide/vpc-support.html
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "IPAllow",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::example-bucket-name/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "NAT Gateway IP"
}
}
}
]
}
If you want to restrict it by VPC endpoint, you can do the following:
{
"Id": "VPCe",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VPCe",
"Action": "s3:PutObject",
"Effect": "Deny",
"Resource": "arn:aws:s3:::example-bucket-name/*",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": [
"VPC Endpoint ID"
]
}
},
"Principal": "*"
}
]
}
Relevant content
asked 2 years ago
- AWS OFFICIALUpdated 8 months ago

Can you please confirm the steps I followed are correct above?
If you can't set up cross-account access then your approach using signed URLs is probably correct. By the way, is it not permitted to modify the bucket policy of the S3 bucket?