Skip to content

Instantly share code, notes, and snippets.

@peterjgrainger
Created August 23, 2023 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjgrainger/d7487b7481b1d9e60f9fe4fb2101ac19 to your computer and use it in GitHub Desktop.
Save peterjgrainger/d7487b7481b1d9e60f9fe4fb2101ac19 to your computer and use it in GitHub Desktop.
Requests per minute
# Use cloudwatch API with Boto3 to get the highest requests per second over a given month for wafv2
import boto3
from datetime import datetime, timedelta
client = boto3.client("cloudwatch")
response = client.get_metric_statistics(
Namespace="AWS/WAFV2",
MetricName="AllowedRequests",
Dimensions=[
{"Name": "WebACL", "Value": "test"},
{"Name": "Region", "Value": "us-east-1"},
{"Name": "Rule", "Value": "ALL"}
],
StartTime="2023-08-22T09:00:00Z",
EndTime="2023-08-23T09:00:00Z",
Period=60,
Statistics=["Sum"]
)
# get the maximum value of requests per second
print(max(response['Datapoints'], key=lambda x: x['Sum']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment