Created
October 24, 2021 12:25
-
-
Save ciscorn/694e3eb5960dc18839ae3907edb5000d to your computer and use it in GitHub Desktop.
Plot Amazon SES Send Statistics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from datetime import datetime, timedelta | |
import zoneinfo | |
import pandas | |
from matplotlib.dates import DateFormatter | |
import matplotlib.pyplot as plt | |
JST = zoneinfo.ZoneInfo("Asia/Tokyo") | |
AWS_KEY = "" | |
AWS_SECRET = "" | |
session = boto3.Session( | |
aws_access_key_id=AWS_KEY, aws_secret_access_key=AWS_SECRET, region_name="us-east-1" | |
) | |
ses = session.client("ses") | |
stats = ses.get_send_statistics() | |
print(stats) | |
df = pandas.DataFrame.from_dict(stats["SendDataPoints"]) | |
df = df.sort_values("Timestamp") | |
df.to_json("ses_send_stats.json", orient="records") | |
df = df[df['Timestamp'] > datetime(2021, 10, 13, 22, tzinfo=JST)] | |
df = df[df['Timestamp'] < datetime(2021, 10, 14, 12, tzinfo=JST)] | |
fig, ax = plt.subplots(figsize=(8, 4)) | |
plt.bar(df['Timestamp'], df['DeliveryAttempts'], timedelta(minutes=15)) | |
ax.set_title("SES Send Statistics") | |
ax.xaxis.set_tick_params(rotation=90, labelsize=10) | |
formatter = DateFormatter('%d %H:%M', tz=JST) | |
ax.xaxis.set_major_formatter(formatter) | |
plt.tight_layout() | |
plt.savefig("stats.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment