Policy Conditions
In addition to controlling which actions users can perform, you can also control under what circumstances those actions are allowed. Policy conditions let you add extra requirements that must be met before access is granted.
IP Address Conditions
One of the most useful conditions is restricting access based on the client's IP address. This is ideal for:
Limiting bucket access to your corporate network
Ensuring backups only run from designated servers
Meeting compliance requirements for data access controls
IpAddress Condition
The IpAddress condition allows access only when requests come from specified IP addresses or ranges:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-bucket",
"arn:aws:s3:::my-bucket/*"
],
"Condition": {
"IpAddress": {
"aws:SourceIp": "203.0.113.0/24"
}
}
}
]
}This policy grants access only to requests originating from the 203.0.113.0/24 network.
NotIpAddress Condition
The NotIpAddress condition allows access from all IP addresses except those specified:
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "198.51.100.0/24"
}
}Supported CIDR Ranges Examples
IP addresses must be specified using CIDR notation:
/32— Single IP (e.g.,203.0.113.25/32)/24— Class C network (e.g.,203.0.113.0/24)/16— Class B network (e.g.,203.0.0.0/16)/8— Class A network (e.g.,203.0.0.0/8)/0— All addresses (e.g.,0.0.0.0/0)