<?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">
      <id>https://wolfgirl.dev/blog/</id>
      <title>PolyWolf's Blog - #devops</title>
      <subtitle
        >all posts tagged "devops" on a blog written by PolyWolf</subtitle
      >
      <icon>/apple-touch-icon.png</icon>
      <link href="/tags/devops/rss.xml" rel="self" />
      <link href="https://wolfgirl.dev/blog/" />
      <updated>2025-08-06T03:27:49Z</updated>
      
    <entry>
      <title><![CDATA[I Am Almost (But Not Quite) Ready To Switch To NixOS]]></title>
      <link rel="alternate" href="https://wolfgirl.dev/blog/2025-08-05-i-am-almost-but-not-quite-ready-to-switch-to-nixos/" />
      <id>https://wolfgirl.dev/blog/2025-08-05-i-am-almost-but-not-quite-ready-to-switch-to-nixos/</id>
      <published>2025-08-06T03:27:49Z</published>
      <updated>2025-08-06T03:27:49Z</updated>
      <summary><![CDATA[Feels like 9000 years, but really it's only been 4 months give or take. The reason it's taken this long is partly my own fault, and partl...]]></summary>
      <content type="html"><![CDATA[<p>Feels like 9000 years, but really it's only been 4 months give or take. The reason it's taken this long is partly my own fault, and partly the fault of Nix itself.</p><p>You see, I like to <a href=https://wolfgirl.dev/blog/2024-09-28-write-your-own-tools/>write my own tools</a>. What that ends up meaning is, in addition to running some "standard" services like a FreshRSS server & a Bluesky PDS on my cloud box, I also run some very non-standard stuff like <a href=https://girl.technology/>https://girl.technology/</a>, <a href=https://wolfgirl.dev/blog/2024-11-08-what-if-anyone-could-use-my-post-composer-/>my post composer</a>, & a small suite of home-grown discord bots. The "standard" services are all nicely packaged thanks to the hard work of many volunteers, but for my own stuff, I <em>have</em> to write my own NixOS modules if i want to run them on NixOS.</p><p>Fortunately, writing custom NixOS modules isn't too challenging once you get a proper setup going<sup class=footnote-ref><a data-footnote-ref href=#fn-getting-a-proper-setup id=fnref-getting-a-proper-setup>1</a></sup>. Unfortunately for present me, past me did not really know about Nix when designing some tools, making assumptions like "of course we will be able to write to the directory my Python code lives in" & "of course <code>$PATH</code> will always be populated with all the programs we could possibly want". <a href=https://girl.technology/>https://girl.technology/</a>, being a Rust project where I tried to follow as many best practices as possible (including packaging in a flake!), was thankfully spared most of this, but my post composer & discord bots... first i took a month to polish up a blog post detailing <a href=https://wolfgirl.dev/blog/2025-05-15-packaging-multiple-dependent-python-modules-using-hatch-nix/>exactly how i was packaging my Python code</a>, just to make sure i understood everything that was going on, <em>then</em> i had to <a href=https://wolfgirl.dev/blog/2025-06-07-i-m-a-nixpkgs-maintainer-now/>become a nixpkgs maintainer</a> because some Python code upstream was broken (another month or so), and only this month did i realize "wait a minute i haven't actually fixed any of the bugs in my own code yet". so i did that. and hoo momma there were lots</p><p>No particular standouts really, just the standard "ah one more <code>substititeInPlace</code>/<code>wrapProgram</code>/dependency for <code>patchShebangsAuto</code>", plus figuring out how to detangle "everything goes into <code>.</code>" into "everything goes into<code>$DATA_DIR</code>"<sup class=footnote-ref><a data-footnote-ref href=#fn-on-standard-stuff id=fnref-on-standard-stuff>2</a></sup>. That and converting a hand-written nginx config to a NixOS nginx module definition is worthy of exactly the time I allotted it (couple hours on a weekend), and yet, uh, just never got around to it 'til now ig 🙃</p><p>Finnicky & annoying & <em>feels</em> bad b/c I already have a perfectly cromulent Ubuntu 24.04 LTS server hosting all my stuff already, and it's been happily chugging along with no complaints. Just a few problems:</p><ol><li>Every time the server reboots I have to ssh in and start a <code>tmux</code> session because all my services run as systemd user services that only run when my user has a session, not on boot.</li><li>Dist upgrades are liable to break all the Python virtual environments I have set up all over the place b/c those have links back to the main Python install.</li></ol><p>Now, was it worth spending all this time just to sand off these few rough edges? Probably not! The one weekend I spent porting Python packages was likely more time than I would spend in the next 2 years managing my current setup. However, while I like to tell myself it's about "opportunities to make my cloud box do things it never even could before", it's really more about the principle of the matter :P</p><p>So! Lessons learned when designing my hacky pile of Python + shell scripts to be more compatible with Nix next time:</p><ul><li>No need to shell out to <code>subprocess.run</code> when something in <code>os.shutil</code> can do the trick</li><li>If you do <code>subprocess.run</code> a shell script, invoke it directly so <code>patchShebangsAuto</code> can do its thing instead of an extra manual <code>substituteInPlace</code> step</li><li>Do NOT just dump state into the current directory, put it somewhere configurable please :)</li></ul><hr><p>Now!! I've finally finished porting all my services to NixOS, even testing them in a VM to make sure (thanks, <code>nixos build-vm</code>!). So why is the article title "Almost Ready To Switch" & not "Have Successfully Switched"? Well... my target is an Oracle Always Free box, so it is <code>aarch64-linux</code>, and my laptop is <code>x86_64-linux</code>, and <a href=https://github.com/NixOS/nixpkgs/issues/177873><code>nixos-rebuild</code> really doesn't like that situation</a><sup class=footnote-ref><a data-footnote-ref href=#fn-nixos-rebuild id=fnref-nixos-rebuild>3</a></sup>. There is a workaround where you use the <code>--fast</code> flag (to disable re-exec of Nix as <code>aarch64-linux</code> on your <code>x86_64-linux</code> host<sup class=footnote-ref><a data-footnote-ref href=#fn-reexec-bug id=fnref-reexec-bug>4</a></sup>) & a remote <code>--build-host</code>, unfortunately negating many of the effects of having a powerful builder locally. Still nice to have all your sources in one place ig.</p><p>It really is a rabbit hole with this Nix thing. "Ah yes just a little more effort and surely <em>then</em> i will have the perfect setup" is a trap that I am currently falling into, and one that I have seen many more experienced Nix users fall into too. Glad it's just a hobby project, at least I'm having fun :)</p><section class=footnotes data-footnotes><ol><li id=fn-getting-a-proper-setup><p>I once had a link to a pretty good tutorial I followed to get this all set up, but I have since lost it... all that remains is what's in my <a href=https://github.com/p0lyw0lf/infrastructure/tree/main/nixos>infrastructure</a> repo + the knowledge in my head that I should probably get into a blogpost some day. TL;DR nixos-infect + plain 'ol nixos-rebuild<sup class=footnote-ref><a data-footnote-ref href=#fn-nixos-rebuild id=fnref-nixos-rebuild-2>3</a></sup> have been a lot more reliable for me than things like nixos-anywhere or nixops. Then again there are bazillion similar blogs on this subject all with conflicting advice and I wasn't able to find the one I wanted by searching, so this would just be publishing into the void lol. <a aria-label="Back to reference 1" class=footnote-backref data-footnote-backref data-footnote-backref-idx=1 href=#fnref-getting-a-proper-setup>↩</a></p></li><li id=fn-on-standard-stuff><p>The other thing is, it was my first time packaging a poorly-written piece of code for Nix, so many of these problems were brand-new for me. Now that I am aware of these problems it is a lot easier to fix but yeah v frustrating the first time around :( <a aria-label="Back to reference 2" class=footnote-backref data-footnote-backref data-footnote-backref-idx=2 href=#fnref-on-standard-stuff>↩</a></p></li><li id=fn-nixos-rebuild><p>Ok so actually maybe nixos-rebuild isn't all that great... <a aria-label="Back to reference 3" class=footnote-backref data-footnote-backref data-footnote-backref-idx=3 href=#fnref-nixos-rebuild>↩</a> <a aria-label="Back to reference 3-2" class=footnote-backref data-footnote-backref data-footnote-backref-idx=3-2 href=#fnref-nixos-rebuild-2>↩<sup class=footnote-ref>2</sup></a></p></li><li id=fn-reexec-bug><p>Fun fact I think the checks for this are broken on the current nixos-unstable and it just goes ahead and tried to re-exec anyway, to disastrous effect. I put up a repository with reproduction steps <a href=https://github.com/p0lyw0lf/nixos-rebuild-bug-repro>here</a>, may try to report an issue later. <a aria-label="Back to reference 4" class=footnote-backref data-footnote-backref data-footnote-backref-idx=4 href=#fnref-reexec-bug>↩</a></p></li></ol></section>]]></content>
      <author>
        <name>PolyWolf</name>
        <uri>https://wolf.girl.technology/</uri>
      </author>
    </entry>
  
    <entry>
      <title><![CDATA[Reducing 404 Errors By Being Less Lazy]]></title>
      <link rel="alternate" href="https://wolfgirl.dev/blog/2025-04-13-reducing-404-errors-by-being-less-lazy/" />
      <id>https://wolfgirl.dev/blog/2025-04-13-reducing-404-errors-by-being-less-lazy/</id>
      <published>2025-04-13T04:07:09Z</published>
      <updated>2025-04-13T04:07:09Z</updated>
      <summary><![CDATA[I had a problem[^1]: every time I posted something to this blog, I immediately got a bunch of 404 errors. To understand why, we must firs...]]></summary>
      <content type="html"><![CDATA[<p>I had a problem<sup class=footnote-ref><a data-footnote-ref href=#fn-1 id=fnref-1>1</a></sup>: every time I posted something to this blog, I immediately got a bunch of 404 errors. To understand why, we must first understand how my crossposter worked:</p><ol><li>Create Mastodon post</li><li>Create Bluesky post</li><li>Create commit in GitHub with the URLs of the above posts, for comment URLs</li><li>GitHub Actions sees the commit and kicks off a build</li></ol><p>The problem with this is, the Mastodon and Bluesky posts were created <em>before</em> my blog post URL went live! Social media platforms like Mastodon and Bluesky like to include URL previews, and naturally they need to fetch the URL to do this. I could sort of tolerate just a few servers and fast-clicking users getting 404s, but uh, every fediverse server that syndicates with mine <em>also</em> fetches this URL very soon after posting, in an infamous "fedi hug of death".</p><p>The only possible fix is to make sure the post URL is live before creating the Mastodon/Bluesky posts. However, I also want to include the Mastodon/Bluesky post URLs in my final post, leading to a bit of a chicken-and-egg problem. I eventually decided it'd be fine to do 2 website rebuilds, one without the comment URLs and one with. Extending my existing publishing process, I thought I'd do this:</p><ol><li>Create commit in GitHub w/ no comment URLs</li><li>GitHub Actions sees this commit and kicks off a build.</li><li>At the end of the build, GitHub Actions hits a webhook on my server, letting it know which post it should continue the process for</li><li>Create Mastodon post</li><li>Create Bluesky post</li><li>Create a second commit in GitHub with the new comment links, with a special commit format telling GitHub not to hit my webhook a second time</li></ol><p>This is janky & nasty but it would probably work. I probably would have done it, too, <strong>if only GitHub Actions wasn't such a pain to work with</strong>. Very simple things like "parse some text out of a commit message" require shelling out to the classic <code>head | cut</code> and doing some nastiness w/ setting output variables, which, just why.</p><p>In my frustration, I had an epiphany: why am i using GitHub Actions at all?? I have a perfectly cromulent server running my crossposter already, so why not... just do the website build on there:</p><ol><li>Create commit in GitHub with no comment links</li><li>Build & publish website, using a simple shell script that my crossposter can wait for before moving onto the next step</li><li>Create Mastodon post</li><li>Create Bluesky post</li><li>Create a second GitHub commit</li><li>Build & publish website again</li></ol><p>lol<sup class=footnote-ref><a data-footnote-ref href=#fn-2 id=fnref-2>2</a></sup>.</p><p>Comparing the <a href=https://github.com/p0lyw0lf/crossposter/blob/a7cc890fa0ee15b67faca6534a16ec6f3996866a/scripts/publish_blog.sh>new <code>publish_blog.sh</code></a><sup class=footnote-ref><a data-footnote-ref href=#fn-3 id=fnref-3>3</a></sup> to the <a href=https://github.com/p0lyw0lf/website/blob/2424c13e617283b928635416fe4d3cb06b26c745/.github/workflows/main.yml>old GitHub Actions workflow</a>, it's actually insane how much incomprehensible boilerplate I've been able to get rid of. Much of it is related to saving/restoring caches, but a lot is also the YAML being very verbose. After replacing it with my own, much more comprehensible <a href=https://github.com/p0lyw0lf/crossposter/blob/a7cc890fa0ee15b67faca6534a16ec6f3996866a/poster/script.py>Python</a> & <a href=https://github.com/p0lyw0lf/crossposter/blob/a7cc890fa0ee15b67faca6534a16ec6f3996866a/shared/config/config.yaml#L23-L24>YAML</a> boilerplate, I understand my own system much better now. <a href=https://wolfgirl.dev/blog/2024-09-28-write-your-own-tools/>Write Your Own Tools</a> strikes again!!</p><section class=footnotes data-footnotes><ol><li id=fn-1><p>I'm writing this post in past-tense because, with this post, I'm now using the new 404-less system! Was hoping it'd work first try, but it did not, and some fast clicking-users may have seen some side-effect posts as I was testing the system in prod oops <a aria-label="Back to reference 1" class=footnote-backref data-footnote-backref data-footnote-backref-idx=1 href=#fnref-1>↩</a></p></li><li id=fn-2><p>The GitHub commits are only so there's always a backup before doing any posting, there's probably a way to do this all in 1 commit, but whatever, I've done enough with this to be lazy again :P <a aria-label="Back to reference 2" class=footnote-backref data-footnote-backref data-footnote-backref-idx=2 href=#fnref-2>↩</a></p></li><li id=fn-3><p>Oh yeah I also switched to <a href=https://rclone.org/s3/#configuration><code>rclone sync</code></a> instead of <code>aws s3 sync</code>, because uploading my entire blog for every post turned out to be what was driving up my AWS costs, not <a href=https://wolfgirl.dev/blog/2025-03-15-i-just-need-to-optimize-my-aws-egress-patterns/>turning on logs</a>, lol. <a aria-label="Back to reference 3" class=footnote-backref data-footnote-backref data-footnote-backref-idx=3 href=#fnref-3>↩</a></p></li></ol></section>]]></content>
      <author>
        <name>PolyWolf</name>
        <uri>https://wolf.girl.technology/</uri>
      </author>
    </entry>
  
    <entry>
      <title><![CDATA[I Just Need To Optimize My AWS Egress Patterns]]></title>
      <link rel="alternate" href="https://wolfgirl.dev/blog/2025-03-15-i-just-need-to-optimize-my-aws-egress-patterns/" />
      <id>https://wolfgirl.dev/blog/2025-03-15-i-just-need-to-optimize-my-aws-egress-patterns/</id>
      <published>2025-03-15T14:41:07Z</published>
      <updated>2025-03-15T14:41:07Z</updated>
      <summary><![CDATA[To preface: I've been doing pretty well for myself at minimizing my cloud spend. I just have a static site in S3 behind CloudFront, so th...]]></summary>
      <content type="html"><![CDATA[<p>To preface: I've been doing pretty well for myself at minimizing my cloud spend. I just have a static site in S3 behind CloudFront, so the following table accounts for all of my spend<sup class=footnote-ref><a data-footnote-ref href=#fn-1 id=fnref-1>1</a></sup>:</p><div class=table-wrapper><table><thead><tr><th align=left>Usage type</th><th align=left>Oct 2024</th><th align=left>Nov 2024</th><th align=left>Dec 2024</th><th align=left>Jan 2025</th><th align=left>Feb 2025</th></tr></thead><tbody><tr><td align=left>S3 Requests-Tier1</td><td align=left>$0.03</td><td align=left>$0.02</td><td align=left>$0.02</td><td align=left>$0.07</td><td align=left>$0.10</td></tr><tr><td align=left>S3 TimedStorage-ByteHrs</td><td align=left>$0.05</td><td align=left>$0.05</td><td align=left>$0.05</td><td align=left>$0.04</td><td align=left>$0.03</td></tr><tr><td align=left>S3 Requests-Tier2</td><td align=left>$0.02</td><td align=left>$0.02</td><td align=left>$0.02</td><td align=left>$0.02</td><td align=left>$0.02</td></tr><tr><td align=left><strong>Total costs</strong></td><td align=left><strong>$0.10</strong></td><td align=left><strong>$0.09</strong></td><td align=left><strong>$0.09</strong></td><td align=left><strong>$0.12</strong></td><td align=left><strong>$0.15</strong></td></tr></tbody></table></div><p>So clearly, I don't <em>need</em> to optimize my spend with it in the pennies n all, but there's still a worrying trend, and I like optimizing, so optimize I shall.</p><h2 id=heading-what-happened-in-january>What Happened In January?<a aria-label="Link to heading 'What Happened In January?'" data-heading-content="What Happened In January?" class=anchor href=#what-happened-in-january></a></h2><p>Looking at CloudWatch metrics for my CloudFront distributions, we see that neither the number of requests nor the number of bytes downloaded lines up with the price increase I'm seeing<sup class=footnote-ref><a data-footnote-ref href=#fn-s3 id=fnref-s3>2</a></sup><sup class=footnote-ref><a data-footnote-ref href=#fn-bots id=fnref-bots>3</a></sup>:</p><figure><div class=table-wrapper><table><tbody><tr><td><p><img alt="Requests summed over 7 day periods. Green spikes in October, later November & early December, then tapers off in January and February. Blue is flat for most the rest, with Red and Orange at the very bottom." src=https://static.wolfgirl.dev/polywolf/blog/019599de-a4ef-7665-97df-7b1373ff6cfa/Screenshot%202025-03-15%20095227.png></p></td><td><p><img alt="Bytes downloaded summed over 7 day periods. Red & Orange spike in December and Feburary, with other smaller spikes still high above Green & Blue." src=https://static.wolfgirl.dev/polywolf/blog/019599de-a4ef-7665-97df-7b1373ff6cfa/Screenshot%202025-03-15%20095254.png></p></td></tr></tbody></table></div><figcaption>Green & Blue are the main sites, and Red & Orange are my static files</figcaption></figure><p>Instead, what I think is happening is that I started <a href=https://wolfgirl.dev/blog/2025-01-19-i-have-numbers-now/>analyzing my CloudFront access logs</a>. Whoops!</p><h2 id=heading-whats-wrong-with-the-access-log-egress-pattern>What's Wrong With The Access Log Egress Pattern?<a aria-label="Link to heading 'What's Wrong With The Access Log Egress Pattern?'" data-heading-content="What's Wrong With The Access Log Egress Pattern?" class=anchor href=#whats-wrong-with-the-access-log-egress-pattern></a></h2><p>I have two hypotheses:</p><ol><li>You're not supposed to put the files from <a href=https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html>CloudFront access logs</a> into <code>{yyyy}/{MM}/{dd}</code> folders, because <code>LIST</code> requests are 10x as expensive as <code>GET</code> requests, or</li><li>There isn't a way to use the S3 access logs w/o incurring this cost, because CloudFront just loves to put a bunch of tiny files in ur bucket, and <code>GET</code>ing all those files will incur costs.</li></ol><p>Unfortunately, I can't really think of any way to solve this that doesn't involve services that are more expensive (Firehose, CloudWatch Logs)<sup class=footnote-ref><a data-footnote-ref href=#fn-2 id=fnref-2>4</a></sup> or fetching the files in some other way (AWS Lambda behind API Gateway behind CloudFront) which would still eat most of the same <code>LIST</code>/<code>GET</code> costs.</p><h2 id=heading-lets-do-some-math>Let's Do Some Math<a aria-label="Link to heading 'Let's Do Some Math'" data-heading-content="Let's Do Some Math" class=anchor href=#lets-do-some-math></a></h2><p>I have about 15000 objects in my log buckets, across 60 days. I check it about once a day, so looking at the <a href=https://aws.amazon.com/s3/pricing/>S3 pricing page</a> & accounting for the slightly nested nature of some of the folders, we get:</p><pre class=syntax-highlighting><code>$ python
Python 3.11.11 (main, Dec  3 2024, 17:20:40) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 15000 * 0.0004 / 1000
0.006
>>> 30 * 65 * 0.005 / 1000
0.00975
</code></pre><p>hrm. That's not right. That should only show up as $0.02 on my bill, and clearly it's more than that, so I'm doing something wrong. Maybe it has to make a <code>HEAD</code> request to check if an object's been updated?</p><pre class=syntax-highlighting><code>>>> 30 * 15000 * 0.0004 / 1000
0.18
</code></pre><p>Now that's roughly the same order of magnitude, but now it's <em>too</em> large. Maybe I'm not actually checking my charts every day, but maybe I'm still doing my math wrong... Wait a minute, what about the <code>PUT</code> requests CloudFront makes to upload these objects in the first place?</p><pre class=syntax-highlighting><code>>>> 15000 * 0.005 / 1000
0.07
</code></pre><p>Bingo, we have a winner. Doesn't like up perfectly because I accidentally nuked part of it once, but yeah that'd do it, especially when combined with the uploads I do to my blog normally. Welp, nothing much I can do about that, mystery solved! So long as I <em>actually</em> run dashboard creation just once a day (or even more if I got that <code>LIST</code> calculation wrong), I think the cost will remain manageable (&lt;$0.20); I've paid a lot more for not understanding the Oracle Cloud "Always Free" tier lol.</p><p>Log ingestion is hard!! Still working at it, GoAccess is really nice but still needs a way to get the data. Same with whatever dashboard software I decide to use next<sup class=footnote-ref><a data-footnote-ref href=#fn-observable id=fnref-observable>5</a></sup>.</p><section class=footnotes data-footnotes><ol><li id=fn-1><p>I host pretty much everything else on an Oracle Cloud Always Free VPS, which is quite beefy, at the expense of having to give Larry Ellison my credit card info & having the threat of the VPS being totally deleted for no reason at any point. Still 100% worth it for me, as you can see, with the rest of my spend in the pennies. <a aria-label="Back to reference 1" class=footnote-backref data-footnote-backref data-footnote-backref-idx=1 href=#fnref-1>↩</a></p></li><li id=fn-s3><p>I know data out from CloudFront isn't a perfect analogue for S3 data charges, but it's what I have since turns out S3 doesn't enable access metrics by default. I've turned them on for my log buckets now, hopefully this doesn't start charging me something ridiculous... <a aria-label="Back to reference 2" class=footnote-backref data-footnote-backref data-footnote-backref-idx=2 href=#fnref-s3>↩</a></p></li><li id=fn-bots><p>Every time I look at this chart I'm reminded I should probably put a <code>robots.txt</code> file in my static sites so scrapers don't download a bunch of files... <a aria-label="Back to reference 3" class=footnote-backref data-footnote-backref data-footnote-backref-idx=3 href=#fnref-bots>↩</a></p></li><li id=fn-2><p>At least I'm pretty sure, looking at their pricing pages vs the S3 page and thinking about what my usage pattern looks like. Can't be 100% certain until I actually tried to build things with them, this is a classic AWS-ism :) <a aria-label="Back to reference 4" class=footnote-backref data-footnote-backref data-footnote-backref-idx=4 href=#fnref-2>↩</a></p></li><li id=fn-observable><p><a href=https://observablehq.com/framework/>Observable Framework</a> looks pretty nice... i &lt;3 niche SSGs <a aria-label="Back to reference 5" class=footnote-backref data-footnote-backref data-footnote-backref-idx=5 href=#fnref-observable>↩</a></p></li></ol></section>]]></content>
      <author>
        <name>PolyWolf</name>
        <uri>https://wolf.girl.technology/</uri>
      </author>
    </entry>
  
    <entry>
      <title><![CDATA[I Have "Numbers" Now]]></title>
      <link rel="alternate" href="https://wolfgirl.dev/blog/2025-01-19-i-have-numbers-now/" />
      <id>https://wolfgirl.dev/blog/2025-01-19-i-have-numbers-now/</id>
      <published>2025-01-19T20:59:14Z</published>
      <updated>2025-01-19T20:59:14Z</updated>
      <summary><![CDATA[My blog is hosted with CloudFront pointed at an S3 bucket, automatically updated to whenever I push a commit to the GitHub repository con...]]></summary>
      <content type="html"><![CDATA[<p>My blog is hosted with CloudFront pointed at an S3 bucket, automatically updated to whenever I push a commit to the GitHub repository containing the sources. Pretty simple in the end, but required a lot of reading AWS blog posts to get set up correctly initially. Now that it's no longer on Cohost, I have the opportunity to look at something I haven't been able to before: <strong><em>numbers</em></strong>. Unfortunately this required reading yet more AWS blog posts.!</p><h2 id=heading-where-do-numbers-come-from>Where Do Numbers Come From?<a aria-label="Link to heading 'Where Do Numbers Come From?'" data-heading-content="Where Do Numbers Come From?" class=anchor href=#where-do-numbers-come-from></a></h2><p>From looking at an automatically-created CloudWatch (AWS's logging/metrics collection service) dashboard, I could see that CloudFront (AWS's CDN service) was already collecting... something...</p><p><img alt="CloudWatch dashboard showing total requests and total bytes downloaded from wolfgirl.dev and static.wolfgirl.dev" src=https://static.wolfgirl.dev/polywolf/blog/0194801b-532b-7224-8ae3-2fdeb7168007/Screenshot%202025-01-19%20151439.png></p><p>Great! So my website is getting hits! But on what pages? That was the question I wanted answered, and this dashboard would not or could not answer it.</p><p>Looking further, I found documentation for <a href=https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/standard-logging.html>how to turn on CloudFront access logs</a>, which would contain the information I wanted in the <code>cs-uri-stem</code> field, among others. The data in CloudWatch currently was just "metrics", not "logs", though. If I wanted to put logs in CloudWatch, it would be... some unknown amount amount of money, based on usage. Given an example on the <a href=https://aws.amazon.com/cloudwatch/pricing/>CloudWatch pricing page</a>, I estimated about $1/mo.</p><p>Now that seems pretty reasonable, no? But currently, I pay just $0.10/mo for S3 storage, and nothing for anything else, so logs alone would 10x my costs :(. I am ruthless about making sure I pay as little as possible for the cloud services I use, so this was a non-starter.</p><p>Fortunately, there is another option: CloudFront can put its access logs directly into an S3 bucket, which I could analyze & rotate at my own convenience! Except... how?</p><h2 id=heading-where-do-numbers-go>Where Do Numbers Go?<a aria-label="Link to heading 'Where Do Numbers Go?'" data-heading-content="Where Do Numbers Go?" class=anchor href=#where-do-numbers-go></a></h2><p>Initially, I thought "oh, I can just write a hacky Python script to download & parse them all". But then the thought of writing a hacky Python script seemed really unappealing to me, so I <a href=https://social.treehouse.systems/@PolyWolf/113851932867864276>lazyweb-ed on Mastodon</a> to see if anyone knew of any pre-built solutions to parse CloudFront logs. Fortunately <a href=https://woof.tech/@unlobito/113851963653376831>someone responded</a> (<a href=https://lobi.to/>unlobito</a>) suggesting a program called <a href=https://goaccess.io/>GoAccess</a><sup class=footnote-ref><a data-footnote-ref href=#fn-1 id=fnref-1>1</a></sup> that looked pretty good. Now, all I had to do was write some hacky Python that calls the following shell script!</p><pre class=syntax-highlighting><code class=language-bash><span class=comment>#!/usr/bin/env bash</span>

<span class=comment># Make it so if any individual step fails, the script exits early, among other things</span>
<span class=function>set</span> <span class=constant>-euo</span> pipefail
<span class=comment># Make it so ** acts as a recursive glob (not default on certain bash-es)</span>
<span class=function>shopt</span> <span class=constant>-s</span> globstar

<span class=keyword>if</span> [[ -z <span class=string>"</span><span class=embedded>${</span><span class=property>AWS_BUCKET_NAME</span><span class=embedded>+x}</span><span class=string>"</span> ]]; <span class=keyword>then</span>
  >&2 <span class=function>echo</span> <span class=string>"Must get bucket passed as AWS_BUCKET_NAME"</span>
  <span class=function>exit</span> 1
<span class=keyword>fi</span>

<span class=property>output_folder</span>=<span class=string>"/tmp/</span><span class=embedded>${</span><span class=property>AWS_BUCKET_NAME</span><span class=embedded>}</span><span class=string>"</span>
<span class=function>mkdir</span> <span class=constant>-p</span> <span class=operator>$</span><span class=property>output_folder</span>
<span class=property>output_file</span>=<span class=string>"/tmp/</span><span class=embedded>${</span><span class=property>AWS_BUCKET_NAME</span><span class=embedded>}</span><span class=string>.html"</span>
<span class=function>touch</span> <span class=operator>$</span><span class=property>output_file</span>

<span class=comment># Download all logs from S3. Must also receive environment variables that allow this to work</span>
<span class=function>aws</span> s3 sync <span class=constant>--delete</span> <span class=string>"s3://</span><span class=embedded>${</span><span class=property>AWS_BUCKET_NAME</span><span class=embedded>}</span><span class=string>"</span> <span class=string>"</span><span class=embedded>${</span><span class=property>output_folder</span><span class=embedded>}</span><span class=string>"</span> <span class=number>1</span>>&2

<span class=comment># Generate the report with GoAccess running inside Docker</span>
<span class=function>zcat</span> <span class=string>"</span><span class=embedded>${</span><span class=property>output_folder</span><span class=embedded>}</span><span class=string>/**/*.gz"</span> <span class=operator>|</span> <span class=function>docker</span> run <span class=constant>--rm</span> <span class=constant>-i</span> <span class=constant>-v</span> <span class=string>"</span><span class=embedded>${</span><span class=property>output_file</span><span class=embedded>}</span><span class=string>:/report.html"</span> <span class=constant>-e</span> LANG=<span class=operator>$</span><span class=property>LANG</span> allinurl/goaccess <span class=constant>-a</span> <span class=constant>-o</span> report.html <span class=constant>--log-format</span> CLOUDFRONT - <span class=number>1</span>>&2

<span class=function>echo</span> <span class=string>"</span><span class=embedded>${</span><span class=property>output_file</span><span class=embedded>}</span><span class=string>"</span></code></pre><p>GoAccess is pretty fast, and S3 doesn't take <em>that</em> long to download<sup class=footnote-ref><a data-footnote-ref href=#fn-2 id=fnref-2>2</a></sup>, so I can get updated reports pretty easily. Now, drumroll please...</p><h2 id=heading-whats-my-most-viewed-page>What's My Most Viewed Page?<a aria-label="Link to heading 'What's My Most Viewed Page?'" data-heading-content="What's My Most Viewed Page?" class=anchor href=#whats-my-most-viewed-page></a></h2><p><img alt="A table showing /blog/rss.xml, /, and /cybersec/rss.xml being the most-hit pages" src=https://static.wolfgirl.dev/polywolf/blog/0194801b-532b-7224-8ae3-2fdeb7168007/Screenshot%202025-01-19%20154654.png></p><p>It's RSS.</p><p>Guess I have a few readers huh! Hi 👋😸</p><h2 id=heading-other-neat-insights-i-didnt-expect>Other Neat Insights I Didn't Expect<a aria-label="Link to heading 'Other Neat Insights I Didn't Expect'" data-heading-content="Other Neat Insights I Didn't Expect" class=anchor href=#other-neat-insights-i-didnt-expect></a></h2><ul><li>Firefox is outsize represented (50%) compared to it's overall market share (3%). Y'all are some nerds huh :3</li><li>The "bot problem" (automated vulnerability scanners, other crawlers) isn't <em>quite</em> a big a problem as I thought. RSS traffic is way higher.</li><li>The list of referring sites is pretty interesting; it's mostly feed syndicators, but seeing the range of ones I didn't know about is cool.</li></ul><p>I'll try not to abuse my newfound power <em>too</em> hard. Nice to have it available tho.</p><section class=footnotes data-footnotes><ol><li id=fn-1><p>Somehow written in C, not Go?? lol <a aria-label="Back to reference 1" class=footnote-backref data-footnote-backref data-footnote-backref-idx=1 href=#fnref-1>↩</a></p></li><li id=fn-2><p>Hopefully, I haven't tested it on days/weeks worth of data, only hours. <a aria-label="Back to reference 2" class=footnote-backref data-footnote-backref data-footnote-backref-idx=2 href=#fnref-2>↩</a></p></li></ol></section>]]></content>
      <author>
        <name>PolyWolf</name>
        <uri>https://wolf.girl.technology/</uri>
      </author>
    </entry>
  
    </feed>
  