RateLimit
Provides a Cloudflare rate limit resource for a given zone. This can be used to limit the traffic you receive zone-wide, or matching more specific types of requests/responses.
Example Usage
using Pulumi;
using Cloudflare = Pulumi.Cloudflare;
class MyStack : Stack
{
public MyStack()
{
var example = new Cloudflare.RateLimit("example", new Cloudflare.RateLimitArgs
{
ZoneId = @var.Cloudflare_zone_id,
Threshold = 2000,
Period = 2,
Match = new Cloudflare.Inputs.RateLimitMatchArgs
{
Request = new Cloudflare.Inputs.RateLimitMatchRequestArgs
{
UrlPattern = $"{@var.Cloudflare_zone}/*",
Schemes =
{
"HTTP",
"HTTPS",
},
Methods =
{
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
},
},
Response = new Cloudflare.Inputs.RateLimitMatchResponseArgs
{
Statuses =
{
200,
201,
202,
301,
429,
},
OriginTraffic = false,
},
},
Action = new Cloudflare.Inputs.RateLimitActionArgs
{
Mode = "simulate",
Timeout = 43200,
Response = new Cloudflare.Inputs.RateLimitActionResponseArgs
{
ContentType = "text/plain",
Body = "custom response body",
},
},
Correlate = new Cloudflare.Inputs.RateLimitCorrelateArgs
{
By = "nat",
},
Disabled = false,
Description = "example rate limit for a zone",
BypassUrlPatterns =
{
$"{@var.Cloudflare_zone}/bypass1",
$"{@var.Cloudflare_zone}/bypass2",
},
});
}
}
Coming soon!
import pulumi
import pulumi_cloudflare as cloudflare
example = cloudflare.RateLimit("example",
zone_id=var["cloudflare_zone_id"],
threshold=2000,
period=2,
match={
"request": {
"urlPattern": f"{var['cloudflare_zone']}/*",
"schemes": [
"HTTP",
"HTTPS",
],
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
],
},
"response": {
"statuses": [
200,
201,
202,
301,
429,
],
"originTraffic": False,
},
},
action={
"mode": "simulate",
"timeout": 43200,
"response": {
"contentType": "text/plain",
"body": "custom response body",
},
},
correlate={
"by": "nat",
},
disabled=False,
description="example rate limit for a zone",
bypass_url_patterns=[
f"{var['cloudflare_zone']}/bypass1",
f"{var['cloudflare_zone']}/bypass2",
])import * as pulumi from "@pulumi/pulumi";
import * as cloudflare from "@pulumi/cloudflare";
const example = new cloudflare.RateLimit("example", {
zoneId: _var.cloudflare_zone_id,
threshold: 2000,
period: 2,
match: {
request: {
urlPattern: `${_var.cloudflare_zone}/*`,
schemes: [
"HTTP",
"HTTPS",
],
methods: [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
],
},
response: {
statuses: [
200,
201,
202,
301,
429,
],
originTraffic: false,
},
},
action: {
mode: "simulate",
timeout: 43200,
response: {
contentType: "text/plain",
body: "custom response body",
},
},
correlate: {
by: "nat",
},
disabled: false,
description: "example rate limit for a zone",
bypassUrlPatterns: [
`${_var.cloudflare_zone}/bypass1`,
`${_var.cloudflare_zone}/bypass2`,
],
});Create a RateLimit Resource
new RateLimit(name: string, args: RateLimitArgs, opts?: CustomResourceOptions);def RateLimit(resource_name, opts=None, action=None, bypass_url_patterns=None, correlate=None, description=None, disabled=None, match=None, period=None, threshold=None, zone_id=None, __props__=None);func NewRateLimit(ctx *Context, name string, args RateLimitArgs, opts ...ResourceOption) (*RateLimit, error)public RateLimit(string name, RateLimitArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args RateLimitArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args RateLimitArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args RateLimitArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
RateLimit Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The RateLimit resource accepts the following input properties:
- Action
Rate
Limit Action Args The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- Period int
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- Threshold int
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- Zone
Id string The DNS zone ID to apply rate limiting to.
- Bypass
Url List<string>Patterns URLs matching the patterns specified here will be excluded from rate limiting.
- Correlate
Rate
Limit Correlate Args Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- Description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- Disabled bool
Whether this ratelimit is currently disabled. Default:
false.- Match
Rate
Limit Match Args Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- Action
Rate
Limit Action The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- Period int
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- Threshold int
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- Zone
Id string The DNS zone ID to apply rate limiting to.
- Bypass
Url []stringPatterns URLs matching the patterns specified here will be excluded from rate limiting.
- Correlate
Rate
Limit Correlate Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- Description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- Disabled bool
Whether this ratelimit is currently disabled. Default:
false.- Match
Rate
Limit Match Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- action
Rate
Limit Action The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- period number
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- threshold number
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- zone
Id string The DNS zone ID to apply rate limiting to.
- bypass
Url string[]Patterns URLs matching the patterns specified here will be excluded from rate limiting.
- correlate
Rate
Limit Correlate Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- disabled boolean
Whether this ratelimit is currently disabled. Default:
false.- match
Rate
Limit Match Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- action
Dict[Rate
Limit Action] The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- period float
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- threshold float
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- zone_
id str The DNS zone ID to apply rate limiting to.
- bypass_
url_ List[str]patterns URLs matching the patterns specified here will be excluded from rate limiting.
- correlate
Dict[Rate
Limit Correlate] Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- description str
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- disabled bool
Whether this ratelimit is currently disabled. Default:
false.- match
Dict[Rate
Limit Match] Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
Outputs
All input properties are implicitly available as output properties. Additionally, the RateLimit resource produces the following output properties:
Look up an Existing RateLimit Resource
Get an existing RateLimit resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: RateLimitState, opts?: CustomResourceOptions): RateLimitstatic get(resource_name, id, opts=None, action=None, bypass_url_patterns=None, correlate=None, description=None, disabled=None, match=None, period=None, threshold=None, zone_id=None, __props__=None);func GetRateLimit(ctx *Context, name string, id IDInput, state *RateLimitState, opts ...ResourceOption) (*RateLimit, error)public static RateLimit Get(string name, Input<string> id, RateLimitState? state, CustomResourceOptions? opts = null)- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
The following state arguments are supported:
- Action
Rate
Limit Action Args The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- Bypass
Url List<string>Patterns URLs matching the patterns specified here will be excluded from rate limiting.
- Correlate
Rate
Limit Correlate Args Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- Description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- Disabled bool
Whether this ratelimit is currently disabled. Default:
false.- Match
Rate
Limit Match Args Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- Period int
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- Threshold int
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- Zone
Id string The DNS zone ID to apply rate limiting to.
- Action
Rate
Limit Action The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- Bypass
Url []stringPatterns URLs matching the patterns specified here will be excluded from rate limiting.
- Correlate
Rate
Limit Correlate Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- Description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- Disabled bool
Whether this ratelimit is currently disabled. Default:
false.- Match
Rate
Limit Match Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- Period int
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- Threshold int
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- Zone
Id string The DNS zone ID to apply rate limiting to.
- action
Rate
Limit Action The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- bypass
Url string[]Patterns URLs matching the patterns specified here will be excluded from rate limiting.
- correlate
Rate
Limit Correlate Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- description string
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- disabled boolean
Whether this ratelimit is currently disabled. Default:
false.- match
Rate
Limit Match Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- period number
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- threshold number
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- zone
Id string The DNS zone ID to apply rate limiting to.
- action
Dict[Rate
Limit Action] The action to be performed when the threshold of matched traffic within the period defined is exceeded.
- bypass_
url_ List[str]patterns URLs matching the patterns specified here will be excluded from rate limiting.
- correlate
Dict[Rate
Limit Correlate] Determines how rate limiting is applied. By default if not specified, rate limiting applies to the clients IP address.
- description str
A note that you can use to describe the reason for a rate limit. This value is sanitized and all tags are removed.
- disabled bool
Whether this ratelimit is currently disabled. Default:
false.- match
Dict[Rate
Limit Match] Determines which traffic the rate limit counts towards the threshold. By default matches all traffic in the zone. See definition below.
- period float
The time in seconds to count matching traffic. If the count exceeds threshold within this period the action will be performed (min: 1, max: 86,400).
- threshold float
The threshold that triggers the rate limit mitigations, combine with period. i.e. threshold per period (min: 2, max: 1,000,000).
- zone_
id str The DNS zone ID to apply rate limiting to.
Supporting Types
RateLimitAction
- Mode string
The type of action to perform. Allowable values are ‘simulate’, ‘ban’, ‘challenge’ and ‘js_challenge’.
- Response
Rate
Limit Action Response Args Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- Timeout int
The time in seconds as an integer to perform the mitigation action. This field is required if the
modeis eithersimulateorban. Must be the same or greater than the period (min: 1, max: 86400).
- Mode string
The type of action to perform. Allowable values are ‘simulate’, ‘ban’, ‘challenge’ and ‘js_challenge’.
- Response
Rate
Limit Action Response Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- Timeout int
The time in seconds as an integer to perform the mitigation action. This field is required if the
modeis eithersimulateorban. Must be the same or greater than the period (min: 1, max: 86400).
- mode string
The type of action to perform. Allowable values are ‘simulate’, ‘ban’, ‘challenge’ and ‘js_challenge’.
- response
Rate
Limit Action Response Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- timeout number
The time in seconds as an integer to perform the mitigation action. This field is required if the
modeis eithersimulateorban. Must be the same or greater than the period (min: 1, max: 86400).
- mode str
The type of action to perform. Allowable values are ‘simulate’, ‘ban’, ‘challenge’ and ‘js_challenge’.
- response
Dict[Rate
Limit Action Response] Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- timeout float
The time in seconds as an integer to perform the mitigation action. This field is required if the
modeis eithersimulateorban. Must be the same or greater than the period (min: 1, max: 86400).
RateLimitActionResponse
- Body string
The body to return, the content here should conform to the content_type.
- Content
Type string The content-type of the body, must be one of: ‘text/plain’, ‘text/xml’, ‘application/json’.
- Body string
The body to return, the content here should conform to the content_type.
- Content
Type string The content-type of the body, must be one of: ‘text/plain’, ‘text/xml’, ‘application/json’.
- body string
The body to return, the content here should conform to the content_type.
- content
Type string The content-type of the body, must be one of: ‘text/plain’, ‘text/xml’, ‘application/json’.
- body str
The body to return, the content here should conform to the content_type.
- content
Type str The content-type of the body, must be one of: ‘text/plain’, ‘text/xml’, ‘application/json’.
RateLimitCorrelate
RateLimitMatch
- Request
Rate
Limit Match Request Args Matches HTTP requests (from the client to Cloudflare). See definition below.
- Response
Rate
Limit Match Response Args Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- Request
Rate
Limit Match Request Matches HTTP requests (from the client to Cloudflare). See definition below.
- Response
Rate
Limit Match Response Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- request
Rate
Limit Match Request Matches HTTP requests (from the client to Cloudflare). See definition below.
- response
Rate
Limit Match Response Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
- request
Dict[Rate
Limit Match Request] Matches HTTP requests (from the client to Cloudflare). See definition below.
- response
Dict[Rate
Limit Match Response] Custom content-type and body to return, this overrides the custom error for the zone. This field is not required. Omission will result in default HTML error page. Definition below.
RateLimitMatchRequest
- Methods List<string>
HTTP Methods, can be a subset [‘POST’,‘PUT’] or all [’_ALL_’]. Default: [’_ALL_’].
- Schemes List<string>
HTTP Schemes, can be one [‘HTTPS’], both [‘HTTP’,‘HTTPS’] or all [’_ALL_’]. Default: [’_ALL_’].
- Url
Pattern string The URL pattern to match comprised of the host and path, i.e. example.org/path. Wildcard are expanded to match applicable traffic, query strings are not matched. Use * for all traffic to your zone. Default: ‘*‘.
- Methods []string
HTTP Methods, can be a subset [‘POST’,‘PUT’] or all [’_ALL_’]. Default: [’_ALL_’].
- Schemes []string
HTTP Schemes, can be one [‘HTTPS’], both [‘HTTP’,‘HTTPS’] or all [’_ALL_’]. Default: [’_ALL_’].
- Url
Pattern string The URL pattern to match comprised of the host and path, i.e. example.org/path. Wildcard are expanded to match applicable traffic, query strings are not matched. Use * for all traffic to your zone. Default: ‘*‘.
- methods string[]
HTTP Methods, can be a subset [‘POST’,‘PUT’] or all [’_ALL_’]. Default: [’_ALL_’].
- schemes string[]
HTTP Schemes, can be one [‘HTTPS’], both [‘HTTP’,‘HTTPS’] or all [’_ALL_’]. Default: [’_ALL_’].
- url
Pattern string The URL pattern to match comprised of the host and path, i.e. example.org/path. Wildcard are expanded to match applicable traffic, query strings are not matched. Use * for all traffic to your zone. Default: ‘*‘.
- methods List[str]
HTTP Methods, can be a subset [‘POST’,‘PUT’] or all [’_ALL_’]. Default: [’_ALL_’].
- schemes List[str]
HTTP Schemes, can be one [‘HTTPS’], both [‘HTTP’,‘HTTPS’] or all [’_ALL_’]. Default: [’_ALL_’].
- url
Pattern str The URL pattern to match comprised of the host and path, i.e. example.org/path. Wildcard are expanded to match applicable traffic, query strings are not matched. Use * for all traffic to your zone. Default: ‘*‘.
RateLimitMatchResponse
- Origin
Traffic bool Only count traffic that has come from your origin servers. If true, cached items that Cloudflare serve will not count towards rate limiting. Default:
true.- Statuses List<int>
HTTP Status codes, can be one [403], many [401,403] or indicate all by not providing this value.
- Origin
Traffic bool Only count traffic that has come from your origin servers. If true, cached items that Cloudflare serve will not count towards rate limiting. Default:
true.- Statuses []int
HTTP Status codes, can be one [403], many [401,403] or indicate all by not providing this value.
- origin
Traffic boolean Only count traffic that has come from your origin servers. If true, cached items that Cloudflare serve will not count towards rate limiting. Default:
true.- statuses number[]
HTTP Status codes, can be one [403], many [401,403] or indicate all by not providing this value.
- origin
Traffic bool Only count traffic that has come from your origin servers. If true, cached items that Cloudflare serve will not count towards rate limiting. Default:
true.- statuses List[Integer]
HTTP Status codes, can be one [403], many [401,403] or indicate all by not providing this value.
Package Details
- Repository
- https://github.com/pulumi/pulumi-cloudflare
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
cloudflareTerraform Provider.