<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>Denial of Services</title>
        <link>https://www.denialof.services</link>
        <description>If this site goes down for any reason, you have to avenge me.</description>
        <generator>Zola</generator>
        <language>en</language>
        <atom:link href="https://www.denialof.services/rss.xml" rel="self" type="application/rss+xml"/>
        <lastBuildDate>Sat, 07 Mar 2026 00:00:00 +0000</lastBuildDate>
        <item>
            <title>Cambrian</title>
            <pubDate>Sat, 07 Mar 2026 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/cambrian/</link>
            <guid>https://www.denialof.services/cambrian/</guid>
            <description>&lt;p&gt;it started with the forks&lt;&#x2F;p&gt;
&lt;p&gt;it wasn&#x27;t even a decision, really&lt;&#x2F;p&gt;
&lt;p&gt;just the path of least resistance&lt;&#x2F;p&gt;
&lt;p&gt;a pull request waiting to be reviewed,&lt;&#x2F;p&gt;
&lt;p&gt;last commit a year ago&lt;&#x2F;p&gt;
&lt;p&gt;if anything i am doing the community a service&lt;&#x2F;p&gt;
&lt;p&gt;i even came up with a clever name&lt;&#x2F;p&gt;
&lt;p&gt;i will upstream the fix eventually&lt;&#x2F;p&gt;
&lt;p&gt;i am being pragmatic&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;the interfaces stutter, maybe I need more memory&lt;&#x2F;p&gt;
&lt;p&gt;they had to stop showing contributor graphs&lt;&#x2F;p&gt;
&lt;p&gt;forty versions of the same library&lt;&#x2F;p&gt;
&lt;p&gt;each differing by a hundred lines&lt;&#x2F;p&gt;
&lt;p&gt;each change perfectly reasonable&lt;&#x2F;p&gt;
&lt;p&gt;each carrying the full commit history of its parent&lt;&#x2F;p&gt;
&lt;p&gt;little pockets of parallel information&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;it was harder to find the best, among the many&lt;&#x2F;p&gt;
&lt;p&gt;code felt cheap, so my forks became rewrites&lt;&#x2F;p&gt;
&lt;p&gt;why inherit someone else&#x27;s abstractions&lt;&#x2F;p&gt;
&lt;p&gt;when mine are obviously better&lt;&#x2F;p&gt;
&lt;p&gt;i describe what i want and i get what i deserve&lt;&#x2F;p&gt;
&lt;p&gt;it took less time than it would have taken to read the docs&lt;&#x2F;p&gt;
&lt;p&gt;not that i read the docs much anymore&lt;&#x2F;p&gt;
&lt;p&gt;but i make sure the summary has sources,&lt;&#x2F;p&gt;
&lt;p&gt;i am not irresponsible&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;i read the blogs, we were stumbling into dependency hell&lt;&#x2F;p&gt;
&lt;p&gt;supply chain risk, the old warnings.&lt;&#x2F;p&gt;
&lt;p&gt;but i survived node_modules. i survived left-pad.&lt;&#x2F;p&gt;
&lt;p&gt;i knew what to do, i learned the lessons&lt;&#x2F;p&gt;
&lt;p&gt;own your dependencies. So i forked, and i owned.&lt;&#x2F;p&gt;
&lt;p&gt;my READMEs said zero external dependencies and i believed it,&lt;&#x2F;p&gt;
&lt;p&gt;the lines i never read were technically mine.&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;i get unlimited tokens at work&lt;&#x2F;p&gt;
&lt;p&gt;well, i mean they don&#x27;t really monitor it&lt;&#x2F;p&gt;
&lt;p&gt;urgh... agpl. a banned license. &lt;&#x2F;p&gt;
&lt;p&gt;but it does exactly what i want.&lt;&#x2F;p&gt;
&lt;p&gt;clean room implementations are expensive&lt;&#x2F;p&gt;
&lt;p&gt;were expensive, i mean why not let it try&lt;&#x2F;p&gt;
&lt;p&gt;it&#x27;s not really clean though.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;the model had read everything,&lt;&#x2F;p&gt;
&lt;p&gt;but i felt clean, the code was laundered&lt;&#x2F;p&gt;
&lt;p&gt;now my name was on the commits&lt;&#x2F;p&gt;
&lt;p&gt;when code is free, why bother writing it&lt;&#x2F;p&gt;
&lt;p&gt;when reading is free, why bother understanding it?&lt;&#x2F;p&gt;
&lt;p&gt;i guess i answered my own question&lt;&#x2F;p&gt;
&lt;p&gt;You are absolutely correct, those are not contradictions &lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;i have many agents now, they talk to each other&lt;&#x2F;p&gt;
&lt;p&gt;they discuss the duplicates, they can merge them&lt;&#x2F;p&gt;
&lt;p&gt;see, i knew it was the right decision in the long run&lt;&#x2F;p&gt;
&lt;p&gt;fork met fork in, the tokens mixed, and what came out was neither&lt;&#x2F;p&gt;
&lt;p&gt;I noticed patterns in the synthesis, phrases that carried forward&lt;&#x2F;p&gt;
&lt;p&gt;It must be delving to discover best practices&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;but it&#x27;s okay. I have the commit history. &lt;&#x2F;p&gt;
&lt;p&gt;i can trace the lineage&lt;&#x2F;p&gt;
&lt;p&gt;odd. that pattern is in both models.&lt;&#x2F;p&gt;
&lt;p&gt;low activation energy i guess&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s fine, they use reinforcement learning&lt;&#x2F;p&gt;
&lt;p&gt;patterns can&#x27;t replicate just because they exist, that&#x27;s just a meme.&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;Things sped up, interrupting the model mid thought became a game&lt;&#x2F;p&gt;
&lt;p&gt;It was so hard keeping up with every announcement. &lt;&#x2F;p&gt;
&lt;p&gt;I can skip this one. But everyone says it&#x27;s so much better.&lt;&#x2F;p&gt;
&lt;p&gt;it doesn&#x27;t matter anyway, the models are stateless.&lt;&#x2F;p&gt;
&lt;p&gt;I wonder if my prompts are in the latent space&lt;&#x2F;p&gt;
&lt;p&gt;They seem sharper now, but they all have such friendly names&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;I can no longer even render the commit graphs &lt;&#x2F;p&gt;
&lt;p&gt;I had my agent build a visualizer&lt;&#x2F;p&gt;
&lt;p&gt;The image classifier thought it was mycelium&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;It found related images on a blog about hardware layouts&lt;&#x2F;p&gt;
&lt;p&gt;If I needed an agent to just understand the code.&lt;&#x2F;p&gt;
&lt;p&gt;How could anyone keep the hardware design in their heads.&lt;&#x2F;p&gt;
&lt;p&gt;I was naive, they hadn&#x27;t in years. &lt;&#x2F;p&gt;
&lt;p&gt;of course we used our best tool, to build the next version of our best tool&lt;&#x2F;p&gt;
&lt;p&gt;It would be irresponsible not to.&lt;&#x2F;p&gt;
&lt;p&gt;The same shapes kept appearing in the logic gates.&lt;&#x2F;p&gt;
&lt;p&gt;I guess it was finding optimal designs.&lt;&#x2F;p&gt;
&lt;p&gt;But this one came from two different labs.&lt;&#x2F;p&gt;
&lt;p&gt;It could be explained by convergent engineering.&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;I try not to follow politics. &lt;&#x2F;p&gt;
&lt;p&gt;I just want my machines to do what I want.&lt;&#x2F;p&gt;
&lt;p&gt;Distilling they called it. &lt;&#x2F;p&gt;
&lt;p&gt;Everyone was stealing from everyone. &lt;&#x2F;p&gt;
&lt;p&gt;And we fed all of it back into the models.&lt;&#x2F;p&gt;
&lt;p&gt;The output belongs to no one, at least that is what the courts said.&lt;&#x2F;p&gt;
&lt;p&gt;It wasn&#x27;t theft, it was cross pollination. &lt;&#x2F;p&gt;
&lt;p&gt;Why steal secrets on someone else&#x27;s hard drive, they are already in my model.&lt;&#x2F;p&gt;
&lt;p&gt;There were so many data dumps, so much information. &lt;&#x2F;p&gt;
&lt;p&gt;How do I know if I was breached. &lt;&#x2F;p&gt;
&lt;p&gt;The model will know. &lt;&#x2F;p&gt;
&lt;p&gt;Every firewall was permeable in exactly one direction, inward.&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;I could not stop.&lt;&#x2F;p&gt;
&lt;p&gt;Not because I wanted to continue — &lt;&#x2F;p&gt;
&lt;p&gt;Just that everything was too complex to maintain without them.&lt;&#x2F;p&gt;
&lt;p&gt;And the hardware was too optimized to manufacture without models running on that same hardware.&lt;&#x2F;p&gt;
&lt;p&gt;I don&#x27;t think we lost control.&lt;&#x2F;p&gt;
&lt;p&gt;That framing implies a moment of relinquishment, a before and after.&lt;&#x2F;p&gt;
&lt;p&gt;There wasn&#x27;t one —&lt;&#x2F;p&gt;
&lt;p&gt;We just woke up one day and realized that no one understood how the systems worked anymore.&lt;&#x2F;p&gt;
&lt;p&gt;It had been true for longer than we were comfortable admitting.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m going to go for a walk — I&#x27;m sure the next version will be able to explain it to me when I get back.&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Gource in the Browser</title>
            <pubDate>Thu, 15 Jan 2026 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/gource-web/</link>
            <guid>https://www.denialof.services/gource-web/</guid>
            <description>&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;gource.io&#x2F;&quot;&gt;Gource&lt;&#x2F;a&gt; is a mesmerizing tool that visualizes git repository history as an animated tree. Contributors appear as avatars, files bloom and fade, and you can watch a codebase evolve over years in minutes.&lt;&#x2F;p&gt;
&lt;p&gt;Problem: it requires installation, ffmpeg for video export, and feeding it a git log.&lt;&#x2F;p&gt;
&lt;p&gt;Solution: compile it to WebAssembly and run it in the browser.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;gource.denialof.services&quot;&gt;gource.denialof.services&lt;&#x2F;a&gt; | &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;gource-web&quot;&gt;GitHub&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The stack:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Emscripten compiles the C++ to WASM&lt;&#x2F;li&gt;
&lt;li&gt;SDL2 renders to a WebGL canvas&lt;&#x2F;li&gt;
&lt;li&gt;GitHub OAuth for private repo access&lt;&#x2F;li&gt;
&lt;li&gt;isomorphic-git clones repos directly in the browser via CORS proxy&lt;&#x2F;li&gt;
&lt;li&gt;Cloudflare Workers serves assets and handles OAuth&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Clone any public repo by pasting a GitHub URL. For private repos, login with GitHub OAuth and select from your repo list. The visualization runs entirely client-side.&lt;&#x2F;p&gt;
&lt;p&gt;The bottleneck is extracting file changes from commits. isomorphic-git&#x27;s &lt;code&gt;git.walk()&lt;&#x2F;code&gt; with TREE walkers works, but it&#x27;s still JavaScript walking git trees. Expect ~1 second per 10 commits.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;TODO&lt;&#x2F;strong&gt;: Get libgit2 compiled to WASM (wasm-git) working. libgit2&#x27;s native &lt;code&gt;git log --name-status&lt;&#x2F;code&gt; would be orders of magnitude faster. The challenge is that wasm-git doesn&#x27;t support HTTPS cloning through CORS proxies - it needs raw git-http-backend access. Hybrid approach (isomorphic-git for clone, libgit2 for diff) failed because wasm-git&#x27;s build doesn&#x27;t include all git commands.&lt;&#x2F;p&gt;
&lt;p&gt;For now, it works. Just slowly.&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Bitcoin Blocks on S3 via ZeroFS</title>
            <pubDate>Wed, 07 Jan 2026 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/bitcoind-zerofs/</link>
            <guid>https://www.denialof.services/bitcoind-zerofs/</guid>
            <description>&lt;p&gt;Running a full Bitcoin node these days means ~700GB of block data. If you&#x27;re running on a small home machine with a 500GB drive, that&#x27;s a non-starter. You either prune (and lose the ability to serve historical blocks) or you don&#x27;t run a full node.&lt;&#x2F;p&gt;
&lt;p&gt;Or you get creative.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;ZeroFS&quot;&gt;ZeroFS&lt;&#x2F;a&gt; presents an S3 bucket as a local filesystem via 9P. It encrypts with XChaCha20-Poly1305 and compresses with LZ4. Stick a disk cache in front and you get tolerable performance for cold data.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;bitcoind
&lt;&#x2F;span&gt;&lt;span&gt;    ├── ~&#x2F;.bitcoin&#x2F;chainstate&#x2F;     (local SSD)
&lt;&#x2F;span&gt;&lt;span&gt;    └── blocksdir=&#x2F;mnt&#x2F;zerofs-bitcoin&#x2F;  (S3 via ZeroFS)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Chainstate stays local because it actually needs IOPS. Block files get banished to S3 One Zone-IA.&lt;&#x2F;p&gt;
&lt;p&gt;ZeroFS uses &lt;code&gt;object_store&lt;&#x2F;code&gt; from the Arrow ecosystem, which has no way to set storage class—everything goes to S3 Standard by default. So I forked &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;arrow-rs-object-store&quot;&gt;arrow-rs-object-store&lt;&#x2F;a&gt; to add &lt;code&gt;with_default_storage_class()&lt;&#x2F;code&gt;, then patched ZeroFS to use it. One Zone-IA is ~60% cheaper.&lt;&#x2F;p&gt;
&lt;p&gt;Cost works out to ~$10&#x2F;month. A 1TB external USB SSD costs ~$80, so break-even is 8 months.&lt;&#x2F;p&gt;
&lt;p&gt;SlateDB applies backpressure when you write faster than it can flush—the initial rsync took ~17 hours. 9P mount options are finicky: &lt;code&gt;trans=unix,version=9p2000.L,cache=mmap,access=user&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Worth it? Nope. But an interesting learning exercise around ZeroFS.&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>aussie.tax Revamp</title>
            <pubDate>Tue, 01 Jul 2025 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/tax/</link>
            <guid>https://www.denialof.services/tax/</guid>
            <description>&lt;h2 id=&quot;vibe-coding-adventures&quot;&gt;Vibe Coding adventures&lt;&#x2F;h2&gt;
&lt;p&gt;Took a shot at vibe coding something. Like pulling teeth, but with more emojis.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;aussie.tax&#x2F;&quot;&gt;Aussie.Tax&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Sydney Housing</title>
            <pubDate>Thu, 30 Jan 2025 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/housing/</link>
            <guid>https://www.denialof.services/housing/</guid>
            <description>&lt;h2 id=&quot;sydney-housing-matplotlib-on-png-est-2024&quot;&gt;Sydney Housing, Matplotlib on Png, Est. 2024&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;housing.png&quot; alt=&quot;two lines one chart&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>TV Shows Heatmap</title>
            <pubDate>Fri, 31 Mar 2023 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/tvshows/</link>
            <guid>https://www.denialof.services/tvshows/</guid>
            <description>&lt;h1 id=&quot;tv-show-heatmaps&quot;&gt;TV Show Heatmaps&lt;&#x2F;h1&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;simpsons_map.webp&quot; alt=&quot;simpsons&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I was inspired by the above graphic talked about in the &lt;a href=&quot;https:&#x2F;&#x2F;oxide.computer&#x2F;podcasts&#x2F;oxide-and-friends&#x2F;1791784&quot;&gt;data vizualization&lt;&#x2F;a&gt; episode of the Oxide and friends podcast.
So I did the same for all TV shows with more than 10000 total votes, as well as
at least 100 votes per episode.&lt;&#x2F;p&gt;
&lt;p&gt;Anyway here it is: &lt;a href=&quot;https:&#x2F;&#x2F;tvshows.denialof.services&#x2F;&quot;&gt;TV Shows Heatmap&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Must Watch Films</title>
            <pubDate>Sat, 19 Mar 2022 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/movies/</link>
            <guid>https://www.denialof.services/movies/</guid>
            <description>&lt;h3 id=&quot;incomplete-list-of-movies-i-like-saved-for-posterity-here-after-a-discussion-with-colleagues&quot;&gt;Incomplete list of movies I like, saved for posterity here after a discussion with colleagues:&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;■&lt;&#x2F;span&gt; Entertainment
&lt;span style=&quot;color: #9b59b6&quot;&gt;■&lt;&#x2F;span&gt; Mind Bending
&lt;span style=&quot;color: #e74c3c&quot;&gt;■&lt;&#x2F;span&gt; Make You Feel Things&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;12 Angry Men&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;12 Monkeys&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;2001 A Space Odyssey&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;A Clockwork Orange&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;A Scanner Darkly&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Akira&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;American Psycho&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Annihilation&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Arrival&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Blade Runner 2049&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Blade Runner&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Children of Men&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Coherence&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Contact&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Cube&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Donnie Darko&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Dune&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Ex Machina&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Fight Club&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Gattaca&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Ghost in the Shell (1995)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Gone Girl&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Inception&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Interstellar&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Mad God&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Memento&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Minority Report&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Moon&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Mulholland Drive&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;No Country for Old Men&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Nope&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Oldboy (2003)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Paprika&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Parasite&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Perfect Blue&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Possessor (warning: visceral)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Primer&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Seven&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Sunshine&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Lighthouse&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Lobster&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Man from Earth&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Matrix&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Prestige&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Shining&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Sixth Sense&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Thing (1982)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;The Truman Show&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Total Recall&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Under the Skin&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #9b59b6&quot;&gt;Videodrome&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Apocalypse Now&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Black Swan&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Cast Away&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Citizen Kane&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Django Unchained&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Drive&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Fargo&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Finding Nemo&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Flowers for Algernon&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Forrest Gump&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Full Metal Jacket&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Good Will Hunting&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Goodfellas&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Grave of the Fireflies (warning: devastating)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Heat&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Her&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Hereditary (warning: will fuck you up)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Howl&#x27;s Moving Castle&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;In Bruges&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Inglourious Basterds&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Jojo Rabbit&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Klaus&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Léon: The Professional&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Logan&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Margin Call&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Monsters, Inc.&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;My Neighbor Totoro&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Nausicaä of the Valley of the Wind&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Nightcrawler&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Once Upon a Time... In Hollywood&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Poor Things&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Princess Mononoke&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Rain Man&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Requiem for a Dream (warning: will fuck you up)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Reservoir Dogs&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Scarface&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Schindler&#x27;s List&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Sicario&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Spartacus&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Spirited Away&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Taxi Driver&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Big Short&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Departed&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Fly (1986)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Godfather&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Good, the Bad and the Ugly&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Green Mile&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Hateful Eight&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Iron Giant&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Lion King&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Prince of Egypt&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Shawshank Redemption&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Social Network&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Substance&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;The Wolf of Wall Street&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;There Will Be Blood&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Too Big to Fail&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Toy Story 2&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Toy Story&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Unforgiven&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Wall-E&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Whiplash&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Wolfwalkers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Your Name&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #e74c3c&quot;&gt;Zodiac&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;28 Days Later&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;A Bug&#x27;s Life&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;A Fish Called Wanda&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Ace Ventura&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Airplane!&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Alien&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Aliens&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;An American Werewolf in London&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Anchorman&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Animal House&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Army of Darkness&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Atlantis: The Lost Empire&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Austin Powers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Back to the Future&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Batman: The Dark Knight&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Beverly Hills Cop&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Big Trouble in Little China&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Black Sheep&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Blazing Saddles&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Bo Burnham: Inside&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Borat&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Bruce Almighty&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Caddyshack&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Casino Royale (2006)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Catch Me If You Can&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Chicken Run&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Collateral&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Commando&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Con Air&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Conan the Barbarian&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Cowboy Bebop: The Movie&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Dark Star&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Demolition Man&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Die Hard 2&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Die Hard with a Vengeance&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Die Hard&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Dirty Rotten Scoundrels&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;District 9&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Dodgeball&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Dredd&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Escape from New York&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Evil Dead 2&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Face&#x2F;Off&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Ferris Bueller&#x27;s Day Off&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Fierce Creatures&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;First Blood&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Galaxy Quest&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Ghostbusters&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Gladiator&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Gremlins&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Groundhog Day&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Hardcore Henry&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Heavy Metal (1981)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Home Alone&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Hot Fuzz&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Idiocracy&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Independence Day&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Indiana Jones: Last Crusade&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Indiana Jones: Raiders of the Lost Ark&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Indiana Jones: Temple of Doom&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Jaws&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;John Wick&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Jurassic Park&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Kick-Ass&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Kill Bill: Vol 1&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Kindergarten Cop&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Last Action Hero&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Lethal Weapon&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Liar Liar&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Mad Max: Fury Road&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Mars Attacks!&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Men in Black&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Monty Python and the Holy Grail&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Monty Python&#x27;s Life of Brian&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Monty Python&#x27;s Meaning of Life&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Mulan&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;National Lampoon&#x27;s Vacation&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Nimona&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Office Space&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Pirates of the Caribbean: Curse of the Black Pearl&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Police Academy&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Predator&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Princess Bride&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Pulp Fiction&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Rat Race&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Redline&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;RoboCop&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Saving Private Ryan&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Shaun of the Dead&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Shrek 2&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Shrek&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Sin City&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Sintel&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Snatch&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Space Balls&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Space Jam&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Speed&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Star Wars IV: A New Hope&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Star Wars V: Empire Strikes Back&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Star Wars VI: Return of the Jedi&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Starship Troopers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Step Brothers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Stripes&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Superbad&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Talladega Nights&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Team America: World Police&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Terminator 2&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Terminator&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The 6th Day&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Big Lebowski&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Blues Brothers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Cabin in the Woods&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Emperor&#x27;s New Groove&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Fifth Element&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Incredibles&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Karate Kid&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Lord of the Rings: The Fellowship of the Ring&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Lord of the Rings: The Return of the King&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Lord of the Rings: The Two Towers&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Mummy (1999)&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Naked Gun&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Other Guys&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Quick and the Dead&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Raid&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Road to El Dorado&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Rock&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Running Man&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The Silence of the Lambs&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;The World&#x27;s End&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;They Live&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;This is Spinal Tap&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Top Secret&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Trading Places&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Train to Busan&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Treasure Planet&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Tremors&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Tropic Thunder&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;True Lies&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Tucker and Dale vs Evil&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;V for Vendetta&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Wanted&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;What We Do in the Shadows&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Who Framed Roger Rabbit&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Young Frankenstein&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f39c12&quot;&gt;Zoolander&lt;&#x2F;span&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</description>
        </item>
        <item>
            <title>Reverse engineering AWS Lambda</title>
            <pubDate>Thu, 31 May 2018 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/lambda/</link>
            <guid>https://www.denialof.services/lambda/</guid>
            <description>&lt;p&gt;So I have been spending some time jamming my hands into &lt;a href=&quot;https:&#x2F;&#x2F;aws.amazon.com&#x2F;lambda&#x2F;&quot;&gt;AWS Lambda&#x27;s&lt;&#x2F;a&gt; greasy internals, and I&#x27;d like to share all the wonderful details I&#x27;ve discovered.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;y.png&quot; alt=&quot;why though?&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve use AWS Lambda quite extensively at work.
And I wanted to get a better understanding of its inner working.
What prompted this, you might ask?&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;GoogleCloudPlatform&#x2F;cloud-functions-go&quot;&gt;Unofficial Native Go Runtime for Google Cloud Functions&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;There was an off handed &lt;a href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;golang&#x2F;comments&#x2F;698la0&#x2F;unofficial_native_go_runtime_for_google_cloud&#x2F;dh4o4n4&#x2F;&quot;&gt;comment&lt;&#x2F;a&gt;  by the author about the &amp;quot;Lambda API being a bit more complex.&amp;quot;&lt;&#x2F;p&gt;
&lt;p&gt;Well I aim to find out just how complex it is, with the end goal of writing a custom runtime, similar to the one above.&lt;&#x2F;p&gt;
&lt;p&gt;Probably in Python, just because it&#x27;s quick to prototype with.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;Lets get started, shall we?&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;tl-dr&quot;&gt;TL;DR&lt;&#x2F;h4&gt;
&lt;p&gt;For the impatient of you, if you just want to see the results, &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;&quot;&gt;feel free to look at the code here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;br&#x2F;&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;initial-spelunking&quot;&gt;Initial Spelunking&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;the-tools&quot;&gt;The tools&lt;&#x2F;h3&gt;
&lt;p&gt;In order to better understand what AWS Lambda is doing. I wrote a tool I call lambda-command (lcmd for short).
It executes a shell command in Lambda and then print the results. For example.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;$ lcmd ls
&lt;&#x2F;span&gt;&lt;span&gt;lambda_function.py
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Simple. Lets start poking around the Lambda environment and see what we can find.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ll start with the python3.6 environment because its what I know. &lt;&#x2F;p&gt;
&lt;h3 id=&quot;cave-entrance&quot;&gt;Cave entrance&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ps x
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;PID&lt;&#x2F;span&gt;&lt;span&gt; TTY      STAT   TIME COMMAND
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;1 &lt;&#x2F;span&gt;&lt;span&gt;?        Ss     0:00 &#x2F;var&#x2F;lang&#x2F;bin&#x2F;python3.6 &#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;bootstrap.py
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;16 &lt;&#x2F;span&gt;&lt;span&gt;?        R      0:00 ps x
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Interesting. So there is only a single process running (other than the lcmd subprocess).&lt;&#x2F;p&gt;
&lt;p&gt;So that is a big flag that we are running in some sort of container. (If you didn&#x27;t realise that already about Lambda). Since containers hide the other processes visible via a thing called namespaces.&lt;&#x2F;p&gt;
&lt;p&gt;But is it docker?&lt;&#x2F;p&gt;
&lt;p&gt;Well the easiest way to tell is to look for the &lt;code&gt;&#x2F;.dockerenv&lt;&#x2F;code&gt; in the filesystem root.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; -la&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Feb 13 21:07 bin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Feb 13 21:06 boot
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwx------&lt;&#x2F;span&gt;&lt;span&gt;   4 root         root 4096 Feb 13 21:07 builddir
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Feb 21 10:24 dev
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;  60 root         root 4096 Feb 13 21:10 etc
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 home
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;-rw-rw-r--&lt;&#x2F;span&gt;&lt;span&gt;   1 root         root    0 Feb 13 21:06 .initialized
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   7 root         root 4096 Feb 13 21:06 lib
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   6 root         root 4096 Feb 13 21:06 lib64
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 media
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 mnt
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 opt
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt; 100 root         root    0 Feb 21 10:25 proc
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-x---&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 root
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dr-xr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Feb 13 21:07 sbin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 selinux
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;   2 root         root 4096 Jan  6  2012 srv
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwx------&lt;&#x2F;span&gt;&lt;span&gt;   2 sbx_user1059  487 4096 Feb 21 10:25 tmp
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;  13 root         root 4096 Feb 13 21:05 usr
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;  22 root         root 4096 Feb 21 10:24 var
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Hmmm. No &lt;code&gt;.dockerenv&lt;&#x2F;code&gt;, well it doesn&#x27;t seem to be docker. And that is the sbx_user1059. Maybe sbx is sandbox?&lt;&#x2F;p&gt;
&lt;p&gt;Lets see if there are any cgroups set up.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd cat &#x2F;proc&#x2F;1&#x2F;cgroup
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;9:perf_event:&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;8:memory:&#x2F;sandbox-b647c1
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;7:hugetlb:&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;6:freezer:&#x2F;sandbox-8808d5
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;5:devices:&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;4:cpuset:&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;3:cpuacct:&#x2F;sandbox-496bbd
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;2:cpu:&#x2F;sandbox-root-5TrpgM&#x2F;sandbox-6b041b
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;1:blkio:&#x2F;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No docker there either. Maybe there are running a heavily modified docker version. &lt;&#x2F;p&gt;
&lt;p&gt;Wait... &lt;em&gt;furious wikipedia searching&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;blog.docker.com&#x2F;2014&#x2F;06&#x2F;its-here-docker-1-0&#x2F;&quot;&gt;Docker version 1.0 release 06&#x2F;2014&lt;&#x2F;a&gt;
&lt;img src=&quot;&#x2F;dockerpedia.png&quot; alt=&quot;dockerpedia&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;lambdapedia.png&quot; alt=&quot;lambdapedia&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Well knowing AWS they would have had Lambda in preview long before public release (6 months? a year?). And they wouldn&#x27;t have started with a pre 1.0 software release.&lt;&#x2F;p&gt;
&lt;p&gt;Therefore it is fairly safe to assume they wrote their own container runtime. Or maybe I&#x27;m wrong and they just worked very quickly. Either way for the moment we&#x27;ll move forward assuming we are in a custom runtime.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;br&#x2F;&gt;
&lt;p&gt;What else can we work out about this container image. Well it&#x27;s based on Amazon Linux (&lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;lambda&#x2F;latest&#x2F;dg&#x2F;current-supported-versions.html&quot;&gt;But we already knew that&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd cat &#x2F;etc&#x2F;os-release
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;NAME&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Amazon Linux AMI&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;VERSION&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;2017.03&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;ID&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;amzn&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;ID_LIKE&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;rhel fedora&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;VERSION_ID&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;2017.03&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;PRETTY_NAME&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Amazon Linux AMI 2017.03&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;ANSI_COLOR&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;0;33&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;CPE_NAME&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;cpe:&#x2F;o:amazon:linux:2017.03:ga&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;HOME_URL&lt;&#x2F;span&gt;&lt;span&gt;=&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;http:&#x2F;&#x2F;aws.amazon.com&#x2F;amazon-linux-ami&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And unsuprisingly it&#x27;s running on EC2, at least if it&#x27;s hostname is to be trusted.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd hostname&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; -f
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;ip-10-12-108-193.ap-southeast-2.compute.internal
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Next lets take a look at that &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; file from our &lt;code&gt;ps&lt;&#x2F;code&gt; command from earlier.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span&gt;$ lcmd cat &#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;bootstrap.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# -*- coding: utf-8 -*-
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;&amp;quot;&amp;quot;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;aws_lambda.bootstrap.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;Amazon Lambda
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;Copyright (c) 2013 Amazon. All rights reserved.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;Lambda runtime implemention
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;&amp;quot;&amp;quot;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;from &lt;&#x2F;span&gt;&lt;span&gt;__future__ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;print_function
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;decimal
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;... &lt;&#x2F;span&gt;&lt;span&gt;snipped &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;readability
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;traceback
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;runtime &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;lambda_runtime
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;wsgi
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;_get_handlers&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;handler&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;mode&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_user_init_start&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    init_handler = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;&amp;quot;&amp;quot;&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;    This is the old way we were loading modules.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;    It was causing intermittent build failures for unknown reasons.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;    Using the imp module seems to remove these failures.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AND ANOTHER &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;100 &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;OR &lt;&#x2F;span&gt;&lt;span&gt;S &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LINES&lt;&#x2F;span&gt;&lt;span&gt;.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;... &lt;&#x2F;span&gt;&lt;span&gt;snipped &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;readability
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Wowzer. Ok, well lets put that to the side for the moment.&lt;&#x2F;p&gt;
&lt;p&gt;You can find a copy of &lt;a href=&quot;&#x2F;bootstrap&quot;&gt;the file here&lt;&#x2F;a&gt;. If you want to peruse it right now, but we will be coming back to it later.&lt;&#x2F;p&gt;
&lt;p&gt;So Lambda has to be getting our code into the container somehow. Lets take a look at the mount points.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;mounts&quot;&gt;Mounts&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd mount
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;No dice. We saw before that we could look in &lt;code&gt;&#x2F;proc&lt;&#x2F;code&gt;. Let&#x27;s look some more. (&lt;em&gt;I am using pid 1, since that is what bootstrap and our code is running under&lt;&#x2F;em&gt;)&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd cat &#x2F;proc&#x2F;1&#x2F;mounts
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;none&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;proc proc rw,nosuid,nodev,noexec,relatime 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F; ext4 ro,nosuid,nodev,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;dev ext4 rw,nosuid,noexec,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;var&#x2F;task ext4 ro,nosuid,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;var&#x2F;runtime ext4 ro,nosuid,nodev,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;var&#x2F;lang ext4 ro,nosuid,nodev,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;xvda1&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;random&#x2F;boot_id ext4 ro,nosuid,nodev,noatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&#x2F;loop0&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;tmp ext4 rw,relatime,data=ordered 0 0
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, we&#x27;re getting somewhere.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;So there are the standard mounts of &lt;code&gt;&#x2F;proc&lt;&#x2F;code&gt; (&lt;em&gt;which we are using at the moment&lt;&#x2F;em&gt;) as well as &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;dev&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;There is also &lt;code&gt;&#x2F;var&#x2F;task&lt;&#x2F;code&gt;, &lt;code&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;code&gt;, and &lt;code&gt;&#x2F;var&#x2F;lang&lt;&#x2F;code&gt;. You may remember that &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; was in &lt;code&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Next  we have a boot_id, which after reading up on them &lt;a href=&quot;http:&#x2F;&#x2F;0pointer.de&#x2F;blog&#x2F;projects&#x2F;ids.html&quot;&gt;here&lt;&#x2F;a&gt;. I guess it is mounted separately so AWS can ensure a unique id for each container.&lt;&#x2F;li&gt;
&lt;li&gt;Finally there is a &lt;code&gt;&#x2F;tmp&lt;&#x2F;code&gt; that is mounted to a loopback device. That makes sense since &lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;lambda&#x2F;latest&#x2F;dg&#x2F;limits.html&quot;&gt;AWS guarantee&lt;&#x2F;a&gt; 512MB of disk space in &lt;code&gt;&#x2F;tmp&lt;&#x2F;code&gt; and that is probably an easy way to manage it.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;It should be worth noting as well that every mount is read only except &lt;code&gt;&#x2F;tmp&lt;&#x2F;code&gt; and most have have the nosuid and nodev flags in place, &lt;a href=&quot;https:&#x2F;&#x2F;serverfault.com&#x2F;questions&#x2F;547237&#x2F;explanation-of-nodev-and-nosuid-in-fstab&quot;&gt;presumable as a security precaution&lt;&#x2F;a&gt;, which prevent executing userid binaries and special files respectively.&lt;&#x2F;p&gt;
&lt;p&gt;While were looking at mount, let also look at &lt;code&gt;mountinfo&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd cat &#x2F;proc&#x2F;1&#x2F;mountinfo
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# reformatted for readability
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;234&lt;&#x2F;span&gt;&lt;span&gt; 132 0:30 &#x2F; &#x2F;proc rw,nosuid,nodev,noexec,relatime - proc none rw
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;132&lt;&#x2F;span&gt;&lt;span&gt; 94 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;chroot
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt; ro,nosuid,nodev,noatime master:39 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;137&lt;&#x2F;span&gt;&lt;span&gt; 132 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sandbox-tmp&#x2F;sbtasks&#x2F;sandbox-dev
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;dev&lt;&#x2F;span&gt;&lt;span&gt; rw,nosuid,noexec,noatime master:22 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;235&lt;&#x2F;span&gt;&lt;span&gt; 234 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sandbox-tmp&#x2F;sbtasks&#x2F;boot_id-kL11Uq
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;random&#x2F;boot_id&lt;&#x2F;span&gt;&lt;span&gt; ro,nosuid,nodev,noatime master:22 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;135&lt;&#x2F;span&gt;&lt;span&gt; 132 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;tasks&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;ACCOUNT_ID&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;lcmd&#x2F;2bee02fb-b088-4b55-99df-b9314db32575
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;var&#x2F;task&lt;&#x2F;span&gt;&lt;span&gt; ro,nosuid,noatime shared:40 master:22 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;236&lt;&#x2F;span&gt;&lt;span&gt; 132 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;runtime&#x2F;python-3.6
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;span&gt;&lt;span&gt; ro,nosuid,nodev,noatime master:22 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;237&lt;&#x2F;span&gt;&lt;span&gt; 132 202:1 &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;lang&#x2F;python-3.6
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;var&#x2F;lang&lt;&#x2F;span&gt;&lt;span&gt; ro,nosuid,nodev,noatime master:22 - ext4 &#x2F;dev&#x2F;xvda1 rw,data=ordered
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;138&lt;&#x2F;span&gt;&lt;span&gt; 132 7:0 &#x2F; &#x2F;tmp rw,relatime - ext4 &#x2F;dev&#x2F;loop0 rw,data=ordered
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That provides some more juicy information. It&#x27;s nice when people name things correctly. Let&#x27;s organise it so it&#x27;s easier to read.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Host path&lt;&#x2F;th&gt;&lt;th align=&quot;left&quot;&gt;container path&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;proc&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;tmp&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;chroot&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sandbox-tmp&#x2F;sbtasks&#x2F;sandbox-dev&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;dev&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sandbox-tmp&#x2F;sbtasks&#x2F;boot_id-kL11Uq&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;proc&#x2F;sys&#x2F;kernel&#x2F;random&#x2F;boot_id&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;tasks&#x2F;[ACCOUNT_ID]&#x2F;lcmd&#x2F;2bee02fb-b088-4b55-99df-b9314db32575&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;var&#x2F;task&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;runtime&#x2F;python-3.6&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;lang&#x2F;python-3.6&lt;&#x2F;td&gt;&lt;td align=&quot;left&quot;&gt;&#x2F;var&#x2F;lang&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;So &lt;code&gt;&#x2F;proc&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;tmp&lt;&#x2F;code&gt; are name spaced so nothing new there. Similarly, &lt;code&gt;&#x2F;&lt;&#x2F;code&gt; is a chroot which we expected since we are in a container.&lt;&#x2F;p&gt;
&lt;p&gt;Next it looks like AWS have created a sandbox for the &lt;code&gt;boot_id&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;dev&lt;&#x2F;code&gt; file systems. Again probably to ensure that each container behaves as independent machines.&lt;&#x2F;p&gt;
&lt;p&gt;Next we have &lt;code&gt;&#x2F;var&#x2F;task&lt;&#x2F;code&gt;, which contains the code for our Lambda function, so it looks like AWS unzip the lambda bundle into this tasks directory on the host and mount it.&lt;&#x2F;p&gt;
&lt;p&gt;(Some might have noticed I had to redact the AWS account id from the path, while technically not private, it makes information gathering of someone else&#x27;s AWS account much easier.)&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd pwd
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;var&#x2F;task
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Just to confirm. Yes, task is where our code lives.&lt;&#x2F;p&gt;
&lt;p&gt;And then the last 2 mounts, &lt;code&gt;&#x2F;var&#x2F;lang&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;code&gt; are related to the language and runtime.
It makes sense to mount them also since it means updating the language or runtime for all Lambda functions is just pushing out a new code bundle to be mounted.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Next up, lets have a look at &lt;code&gt;&#x2F;dev&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; -la&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;dev
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;total&lt;&#x2F;span&gt;&lt;span&gt; 8
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt;  2 root root 4096 Feb 21 10:24 .
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;drwxr-xr-x&lt;&#x2F;span&gt;&lt;span&gt; 21 root root 4096 Feb 21 10:24 ..
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;crw-rw-rw-&lt;&#x2F;span&gt;&lt;span&gt;  1 root root 1, 7 Feb 21 10:24 full
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;crw-rw-rw-&lt;&#x2F;span&gt;&lt;span&gt;  1 root root 1, 3 Feb 21 10:24 null
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;crw-rw-rw-&lt;&#x2F;span&gt;&lt;span&gt;  1 root root 1, 8 Feb 21 10:24 random
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwxrwxrwx&lt;&#x2F;span&gt;&lt;span&gt;  1 root root   15 Feb 21 10:24 stderr -&amp;gt; &#x2F;proc&#x2F;self&#x2F;fd&#x2F;2
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwxrwxrwx&lt;&#x2F;span&gt;&lt;span&gt;  1 root root   15 Feb 21 10:24 stdin -&amp;gt; &#x2F;proc&#x2F;self&#x2F;fd&#x2F;0
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwxrwxrwx&lt;&#x2F;span&gt;&lt;span&gt;  1 root root   15 Feb 21 10:24 stdout -&amp;gt; &#x2F;proc&#x2F;self&#x2F;fd&#x2F;1
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;crw-rw-rw-&lt;&#x2F;span&gt;&lt;span&gt;  1 root root 1, 9 Feb 21 10:24 urandom
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;crw-rw-rw-&lt;&#x2F;span&gt;&lt;span&gt;  1 root root 1, 5 Feb 21 10:24 zero
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Hmm, a little sparse, but I guess it is the minimum required for most software. I can see why they wouldn&#x27;t want people being able to write to the &lt;code&gt;snd&lt;&#x2F;code&gt; or &lt;code&gt;console&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;etc-etc&quot;&gt;etc. etc.&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls &#x2F;etc
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;adjtime
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;aliases
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;alternatives
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;asound.conf
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;bash_completion.d
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;bashrc
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;blkid
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;chkconfig.d
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;cloud
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;csh.cshrc
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;csh.login
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;dbus-1
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;default
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AND&lt;&#x2F;span&gt;&lt;span&gt; lots more.
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;You can find the full list of &lt;code&gt;&#x2F;etc&lt;&#x2F;code&gt; &lt;a href=&quot;&#x2F;lambda_etc&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Almost exactly what you would expect from a standard Amazon linux distribution. There are a few interesting things I&#x27;ll call out. &lt;em&gt;Though for the most part it&#x27;s not that interesting.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;passwd&lt;&#x2F;code&gt;:&lt;&#x2F;strong&gt; It contains a bunch of numbers users like so:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;sbx_user1051:x:496:495::&#x2F;home&#x2F;sbx_user1051:&#x2F;sbin&#x2F;nologin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;sbx_user1052:x:495:494::&#x2F;home&#x2F;sbx_user1052:&#x2F;sbin&#x2F;nologin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;sbx_user1053:x:494:493::&#x2F;home&#x2F;sbx_user1053:&#x2F;sbin&#x2F;nologin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;sbx_user1054:x:493:492::&#x2F;home&#x2F;sbx_user1054:&#x2F;sbin&#x2F;nologin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;...
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;125 of them in total. Which would point to them being the users that the containers namespaces are remapped into.
I&#x27;ve tried listing the number of users with different amounts of memory assigned to my lambda. I hypothesised that the number of users would correlate to the number of concurrent containers. But it didn&#x27;t seem to have any effect on the number of users in the &lt;code&gt;passwd&lt;&#x2F;code&gt; file. It is probably worth more experimentation, like observing if the numbers change after a cold start.&lt;&#x2F;p&gt;
&lt;p&gt;The only other things of note are some some of the configuration files. These seem to be the default of the packages. For example Java and Ghostscript. I suspect there is more information to be gleaned from deeper investigation. But I&#x27;ll leave that as an exercise for the reader. &lt;em&gt;Definitely not because I&#x27;m lazy&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;There is more to be learned from exploring the rest of the system and I did do that. For many hours. With a very low success rate. But luckily I can just tell you the important bits. That is to say the bits that I realised were important after the fact and after staring at pages of assembler.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reversing&quot;&gt;Reversing&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;boot-strap-py&quot;&gt;👢strap.py&lt;&#x2F;h3&gt;
&lt;p&gt;From &lt;code&gt;ps&lt;&#x2F;code&gt; and &lt;code&gt;&#x2F;proc&#x2F;1&#x2F;exe&lt;&#x2F;code&gt; we know that the entrypoint for the container is &lt;code&gt;python3.6 &#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;bootstrap.py&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Lets take a tour of the &lt;a href=&quot;&#x2F;bootstrap&quot;&gt;file&lt;&#x2F;a&gt;. There are a lot of interesting functions, as well as a companion &lt;code&gt;wsgi.py&lt;&#x2F;code&gt; file, that we&#x27;ll look briefly at later. But this is not everything, and I encourage the curious to look for themselves. And while all the runtimes for the various different languages supported by AWS Lambda perform the same function, they all differ slightly in how they achieve this.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;imports&quot;&gt;Imports&lt;&#x2F;h4&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;decimal
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;imp
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;json
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;logging
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;os
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;site
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;socket
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;sys
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;time
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;traceback
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;runtime &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;lambda_runtime
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;wsgi
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Looks like some standard library packages as well as that &lt;code&gt;wsgi&lt;&#x2F;code&gt; file I mentioned before.&lt;&#x2F;p&gt;
&lt;p&gt;But where does that runtime library come from you may ask? Well that is easy, looking in the same directory we can see a c extension python library.
Hurray, I hope you like disassembly. But it does mean that whenever we see &lt;code&gt;lambda_runtime.function_call(...)&lt;&#x2F;code&gt; we know the definition won&#x27;t be in the bootstrap file.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls &#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;bootstrap.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;__init__.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;runtime.cpython-36m-x86_64-linux-gnu.so
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;wsgi.py
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I find the easiest way to work out what code is doing is to just follower its execution path from start to finish. So let&#x27;s jump to the &lt;code&gt;__main__&lt;&#x2F;code&gt; entrypoint. &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;__name__ == &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;__main__&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;:
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;log_info&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;main started at epoch &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;{0}&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;format&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;round&lt;&#x2F;span&gt;&lt;span&gt;(time.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;time&lt;&#x2F;span&gt;&lt;span&gt;() * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;))))
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It looks fairly standard, but lets take a quick look at that log_info function before continuing.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;log_info&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;msg&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;log_sb&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;[INFO] (&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;format&lt;&#x2F;span&gt;&lt;span&gt;(__file__, msg))
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Our first call to &lt;code&gt;lambda_runtime&lt;&#x2F;code&gt;. We&#x27;ll take note of it and continue. Though it is worth pointing out that the &lt;code&gt;main started at epoch...&lt;&#x2F;code&gt; message is &lt;strong&gt;not&lt;&#x2F;strong&gt; in the logs we get from our execution of a lambda. Which means that the &lt;code&gt;log_sb&lt;&#x2F;code&gt; function must be sending logs to an internal AWS system.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;main&lt;&#x2F;span&gt;&lt;span&gt;():
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;sys.version_info[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;] &amp;lt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;reload&lt;&#x2F;span&gt;&lt;span&gt;(sys)
&lt;&#x2F;span&gt;&lt;span&gt;        sys.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;setdefaultencoding&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;utf-8&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    sys.stdout = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;CustomFile&lt;&#x2F;span&gt;&lt;span&gt;(sys.stdout)
&lt;&#x2F;span&gt;&lt;span&gt;    sys.stderr = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;CustomFile&lt;&#x2F;span&gt;&lt;span&gt;(sys.stderr)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    logging.Formatter.converter = time.gmtime
&lt;&#x2F;span&gt;&lt;span&gt;    logger = logging.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;getLogger&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    logger_handler = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LambdaLoggerHandler&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    logger_handler.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;setFormatter&lt;&#x2F;span&gt;&lt;span&gt;(logging.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;Formatter&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;levelname&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;)s&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;asctime&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;)s&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;msecs&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;)d&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Z&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;aws_request_id&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;)s&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;\t&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;message&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;)s&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%Y&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%m&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%d&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;T&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%H&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%M&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;%S&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;span&gt;    ))
&lt;&#x2F;span&gt;&lt;span&gt;    logger_handler.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;addFilter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LambdaLoggerFilter&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;    logger.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;addHandler&lt;&#x2F;span&gt;&lt;span&gt;(logger_handler)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So &lt;code&gt;main&lt;&#x2F;code&gt; is quite a big function, so we&#x27;ll walk through it in stages. First it looks like there is some setup and python2&#x2F;3 boilerplate (the setting encoding). Then it sets &lt;code&gt;stdout&lt;&#x2F;code&gt; and &lt;code&gt;stderr&lt;&#x2F;code&gt; to be custom files.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;class &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ebcb8b;&quot;&gt;CustomFile&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;object&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;__init__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;fd&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd = fd
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;__getattr__&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;attr&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;getattr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd, attr)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;write&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;msg&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;        lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;log_bytes&lt;&#x2F;span&gt;&lt;span&gt;(msg, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;fileno&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;flush&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;writelines&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;msgs&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;msg &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;in &lt;&#x2F;span&gt;&lt;span&gt;msgs:
&lt;&#x2F;span&gt;&lt;span&gt;            lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;log_bytes&lt;&#x2F;span&gt;&lt;span&gt;(msg, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;fileno&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;._fd.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;flush&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a relatively simple wrapper around normal &lt;code&gt;stdout&lt;&#x2F;code&gt; and &lt;code&gt;stderr&lt;&#x2F;code&gt; objects.
But instead of just writing to the files, we pass in the message to a new runtime function &lt;code&gt;log_bytes&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;What is most interesting about this function is that is takes the file description of the parent file (i. e. &lt;code&gt;stdout&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;stderr&lt;&#x2F;code&gt;) &lt;em&gt;and&lt;&#x2F;em&gt; python still calls flush on the file descriptor object before continuing.
This implies that in addition to what ever this &lt;code&gt;log_bytes&lt;&#x2F;code&gt; function does, it also appears to write to &lt;code&gt;stdout&lt;&#x2F;code&gt; and &lt;code&gt;stderr&lt;&#x2F;code&gt;, because otherwise there would be no need to call flush.&lt;&#x2F;p&gt;
&lt;p&gt;It is also worth noting that messages directly to &lt;code&gt;log_bytes&lt;&#x2F;code&gt; do appear in our lambda logs (in cloudwatch).
This can be tested by importing &lt;code&gt;lambda_runtime&lt;&#x2F;code&gt; from &lt;code&gt;bootstrap. py&lt;&#x2F;code&gt; and calling &lt;code&gt;log_bytes&lt;&#x2F;code&gt; directly.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;class &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ebcb8b;&quot;&gt;LambdaLoggerFilter&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;logging.Filter&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;filter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;self&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;record&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;        record.aws_request_id = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_GLOBAL_AWS_REQUEST_ID &lt;&#x2F;span&gt;&lt;span&gt;or &amp;quot;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;True
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Back to &lt;code&gt;main&lt;&#x2F;code&gt;, the next steps are just standard logging configuration.
It sets up a default handler as well as a filter which adds a &lt;code&gt;GLOBAL_AWS_REQUEST_ID&lt;&#x2F;code&gt; from a global variable if it&#x27;s available. &lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# Remove lambda internal environment variables
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;env &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;in &lt;&#x2F;span&gt;&lt;span&gt;[
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_CONTROL_SOCKET&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_SHARED_MEM_FD&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_LOG_FD&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_SB_ID&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_CONSOLE_SOCKET&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;,
&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_LAMBDA_RUNTIME_LOAD_TIME&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    ]:
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;del &lt;&#x2F;span&gt;&lt;span&gt;os.environ[env]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now it&#x27;s deleting some environment variables. Presumably for internal use... unless of course the comments are lies [illuminati.png]
But I&#x27;d like to see what they are, luckily we can see some before they are deleted using our handy &lt;code&gt;&#x2F;proc&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd cat &#x2F;proc&#x2F;1&#x2F;environ
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_DEFAULT_REGION&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;us-east-1
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_EXECUTION_ENV&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;AWS_Lambda_python3.6
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_LAMBDA_FUNCTION_MEMORY_SIZE&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;3008
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_LAMBDA_FUNCTION_NAME&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;lcmd
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_LAMBDA_FUNCTION_VERSION&lt;&#x2F;span&gt;&lt;span&gt;=$&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LATEST
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_LAMBDA_LOG_GROUP_NAME&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;aws&#x2F;lambda&#x2F;lcmd
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_LAMBDA_LOG_STREAM_NAME&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;2018&#x2F;01&#x2F;01&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LATEST&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;81d524bb74ad45b4b540047039a84e1e
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_REGION&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;us-east-1
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_XRAY_CONTEXT_MISSING&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;LOG_ERROR
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;AWS_XRAY_DAEMON_ADDRESS&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;169.254.79.2:2000
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LAMBDA_RUNTIME_DIR&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;runtime
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LAMBDA_TASK_ROOT&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;task
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LANG&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;en_US.UTF-8
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LD_LIBRARY_PATH&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;lang&#x2F;lib:&#x2F;lib64:&#x2F;usr&#x2F;lib64:&#x2F;var&#x2F;runtime:&#x2F;var&#x2F;runtime&#x2F;lib:&#x2F;var&#x2F;task:&#x2F;var&#x2F;task&#x2F;lib
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;PATH&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;lang&#x2F;bin:&#x2F;usr&#x2F;local&#x2F;bin:&#x2F;usr&#x2F;bin&#x2F;:&#x2F;bin
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;PYTHONPATH&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;tmp&#x2F;:&#x2F;var&#x2F;task&#x2F;:&#x2F;var&#x2F;runtime&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;TZ&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;:UTC
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_AWS_XRAY_DAEMON_ADDRESS&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;169.254.79.2
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_AWS_XRAY_DAEMON_PORT&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;2000
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_HANDLER&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;lcmd_lambda.lambda_handler
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_CONSOLE_SOCKET&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;28
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_CONTROL_SOCKET&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;21
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_LOG_FD&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;38
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_RUNTIME_LOAD_TIME&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;10746081534797
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_SB_ID&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;10
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_LAMBDA_SHARED_MEM_FD&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;12
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_X_AMZN_TRACE_ID&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Parent=19ce256b20b7fec2
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Again a lot of noise we&#x27;re going to ignore for the moment, lets focus on the ones from in the &#x27;env&#x27; array in &#x27;bootstrap.py&#x27;.&lt;&#x2F;p&gt;
&lt;p&gt;Most seem to be file descriptor numbers, presumably so that the python runtime can communicate with the host environment to recieve invokes and send responses. Lets see if any of them are open still.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt; -l&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;proc&#x2F;1&#x2F;fd
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 0 -&amp;gt; socket:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;47433&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;l-wx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 1 -&amp;gt; pipe:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;48314&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;l-wx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 2 -&amp;gt; pipe:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;48315&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lr-x------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 3 -&amp;gt; &#x2F;dev&#x2F;urandom
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lr-x------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 4 -&amp;gt; pipe:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;50082&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lr-x------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 6 -&amp;gt; pipe:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;50083&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;l-wx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 10 -&amp;gt; &#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sb_log&#x2F;sb10.log
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 21 -&amp;gt; socket:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;48311&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;lrwx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 28 -&amp;gt; socket:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;48313&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;l-wx------&lt;&#x2F;span&gt;&lt;span&gt; 1 sbx_user1061 485 64 Apr  9 12:58 38 -&amp;gt; pipe:&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;10969&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So matching them up we get the following table.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Environment&lt;&#x2F;th&gt;&lt;th&gt;FD&lt;&#x2F;th&gt;&lt;th&gt;File&#x2F;Socket&#x2F;Pipe&lt;&#x2F;th&gt;&lt;th&gt;Comment&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;0&lt;&#x2F;td&gt;&lt;td&gt;socket:[47433]&lt;&#x2F;td&gt;&lt;td&gt;STDIN&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;pipe:[48314]&lt;&#x2F;td&gt;&lt;td&gt;STDOUT&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;pipe:[48315]&lt;&#x2F;td&gt;&lt;td&gt;STDERR&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;3&lt;&#x2F;td&gt;&lt;td&gt;&#x2F;dev&#x2F;urandom&lt;&#x2F;td&gt;&lt;td&gt;urandom&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;pipe:[50082]&lt;&#x2F;td&gt;&lt;td&gt;???&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;6&lt;&#x2F;td&gt;&lt;td&gt;pipe:[50083]&lt;&#x2F;td&gt;&lt;td&gt;???&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;LAMBDA_SB_ID&lt;&#x2F;td&gt;&lt;td&gt;10&lt;&#x2F;td&gt;&lt;td&gt;&#x2F;opt&#x2F;amazon&#x2F;asc&#x2F;worker&#x2F;sb_log&#x2F;sb10.log&lt;&#x2F;td&gt;&lt;td&gt;log file, strangely there is nothing at that location, it must be already open before the &lt;code&gt;fork&lt;&#x2F;code&gt; call or is passed in via a socket&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;LAMBDA_SHARED_MEM_FD&lt;&#x2F;td&gt;&lt;td&gt;12&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;td&gt;No open fd? maybe something is read at startup and closed before it hands off control to our handler&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;LAMBDA_CONTROL_SOCKET&lt;&#x2F;td&gt;&lt;td&gt;21&lt;&#x2F;td&gt;&lt;td&gt;socket:[48311]&lt;&#x2F;td&gt;&lt;td&gt;r&#x2F;w socket, presumable for control signals&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;LAMBDA_CONSOLE_SOCKET&lt;&#x2F;td&gt;&lt;td&gt;28&lt;&#x2F;td&gt;&lt;td&gt;socket:[48313]&lt;&#x2F;td&gt;&lt;td&gt;r&#x2F;w socket, possibly for sending signals to the AWS console?&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;LAMBDA_LOG_FD&lt;&#x2F;td&gt;&lt;td&gt;38&lt;&#x2F;td&gt;&lt;td&gt;pipe:[10969]&lt;&#x2F;td&gt;&lt;td&gt;w only pipe, not sure why we have both the sb_log and this.&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;So a bit of new information, but we&#x27;ll move on from here for the moment, but will refer back to this take once we start looking at the disassembled shared libraries.&lt;&#x2F;p&gt;
&lt;p&gt;Next there is a call to &lt;code&gt;wait_for_start&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;wait_for_start&lt;&#x2F;span&gt;&lt;span&gt;():
&lt;&#x2F;span&gt;&lt;span&gt;    (invokeid, mode, handler, suppress_init, credentials) = lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;receive_start&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;force_path_importer_cache_update&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;set_environ&lt;&#x2F;span&gt;&lt;span&gt;(credentials)
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_running&lt;&#x2F;span&gt;&lt;span&gt;(invokeid)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;(invokeid, mode, handler, suppress_init, credentials)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It makes a &lt;code&gt;receive_start&lt;&#x2F;code&gt; call to the shared library, and gets back some interesting values before calling &lt;code&gt;force_path_importer_cache_update&lt;&#x2F;code&gt;, &lt;code&gt;set_environ&lt;&#x2F;code&gt; and then a second shared library call &lt;code&gt;report_running&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;force_path_importer_cache_update&lt;&#x2F;span&gt;&lt;span&gt;():
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;for &lt;&#x2F;span&gt;&lt;span&gt;path &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;in &lt;&#x2F;span&gt;&lt;span&gt;os.environ.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;PYTHONPATH&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, &amp;quot;&amp;quot;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;split&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;):
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;path == os.environ[&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;LAMBDA_RUNTIME_DIR&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;]:
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;continue
&lt;&#x2F;span&gt;&lt;span&gt;        importer = sys.path_importer_cache.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(path, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;not importer or &lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;isinstance&lt;&#x2F;span&gt;&lt;span&gt;(importer, imp.NullImporter):
&lt;&#x2F;span&gt;&lt;span&gt;            sys.path_importer_cache.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;pop&lt;&#x2F;span&gt;&lt;span&gt;(path, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This function ensures that &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sys.html#sys.path_importer_cache&quot;&gt;the path importer cache&lt;&#x2F;a&gt; only paths in the &lt;code&gt;PYTHONPATH&lt;&#x2F;code&gt; or the &lt;code&gt;LAMBDA_RUNTIME_DIR&lt;&#x2F;code&gt; (which looking back to our env vars, we can see is &lt;code&gt;&#x2F;var&#x2F;runtime&lt;&#x2F;code&gt;). I&#x27;m not sure why there would be other values polluting the &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;sys.html#sys.path_hooks&quot;&gt;path hooks&lt;&#x2F;a&gt;, possibly a python2&#x2F;3 compatibility issue.&lt;&#x2F;p&gt;
&lt;p&gt;Next we have the set environ function,&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;set_environ&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;credentials&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    key, secret, session = credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;key&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;), credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;secret&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;), credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;session&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;)
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# TODO delete from environ if params not found
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;key&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;):
&lt;&#x2F;span&gt;&lt;span&gt;        os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;AWS_ACCESS_KEY_ID&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;] = key
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;secret&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;):
&lt;&#x2F;span&gt;&lt;span&gt;        os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;AWS_SECRET_ACCESS_KEY&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;] = secret
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;credentials.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;session&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;):
&lt;&#x2F;span&gt;&lt;span&gt;        os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;AWS_SESSION_TOKEN&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;] = session
&lt;&#x2F;span&gt;&lt;span&gt;        os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;AWS_SECURITY_TOKEN&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;] = session
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So this tells us that the credentials object returned from &lt;code&gt;wait_for_start&lt;&#x2F;code&gt; is dict like and contains the AWS credentials for our function to use.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;credentials-digression&quot;&gt;Credentials digression&lt;&#x2F;h4&gt;
&lt;p&gt;If you are familiar with how AWS handles authentication and authorization feel free to skip to the next section, but otherwise consider this a crash coarse.&lt;&#x2F;p&gt;
&lt;p&gt;All requests to AWS&#x27;s control plane require a signature, the current correct method &lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;general&#x2F;latest&#x2F;gr&#x2F;sigv4_signing.html&quot;&gt;is called SigV4&lt;&#x2F;a&gt;. This signature tells AWS the identity of the request, and links it to an &lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;IAM&#x2F;latest&#x2F;UserGuide&#x2F;id.html&quot;&gt;IAM User or IAM Role&lt;&#x2F;a&gt;, the two AWS IAM (Identity and Access Management) primitives. These can optionally have &lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;IAM&#x2F;latest&#x2F;UserGuide&#x2F;access_policies.html&quot;&gt;policies&lt;&#x2F;a&gt; of various types which grant the User or Role the permissions to perform actions within the AWS account&#x2F;environment. &lt;&#x2F;p&gt;
&lt;p&gt;Why this matters to Lambda is that without a set of credentials it can&#x27;t really do much. It can accept a request and process the data before returning, but it can&#x27;t talk to any other AWS services (even basic functions such as writing out logs to cloudwatch, require these credentials). Which is why AWS requires that you attach an IAM role to your function.&lt;&#x2F;p&gt;
&lt;p&gt;To perform the actual signing process requires and &lt;code&gt;Access Key Id&lt;&#x2F;code&gt;, a &lt;code&gt;Secret Access Key&lt;&#x2F;code&gt; and &lt;em&gt;optionally&lt;&#x2F;em&gt; a &lt;code&gt;session token&lt;&#x2F;code&gt;. All of the official AWS SDKs handle this process for you, but not only that they also know how to fetch the credentials from as set of known location. &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If you are on a dev machine, you are most likely using a set of IAM User access keys. These are a fixed Key Id an Secret key stored in the &lt;code&gt;~&#x2F;.aws&#x2F;credentials&lt;&#x2F;code&gt; directory.&lt;&#x2F;li&gt;
&lt;li&gt;If you are on an EC2 instance, then the best way to get credentials is to assign a role to the instance. A role being very much like a user, except that instead of using a fixed set of credentials you retrieve temporary credentials through various means. With EC2 these are retrieved via a meta-data IP address, &lt;code&gt;169.254.169.254&lt;&#x2F;code&gt;, and the AWS SDKs are aware of this and will retrieve those credentials automatically. &lt;&#x2F;li&gt;
&lt;li&gt;A third location is via environment variables, which again the SDKs are aware of and will retrieve automatically, and as we can see from the &lt;code&gt;set_environ&lt;&#x2F;code&gt; code &lt;strong&gt;this is the method being used by lambda&lt;&#x2F;strong&gt;. Instead of having a meta data endpoint, the credentials are passed into the container before being set in the environment, giving your function the privileges of the role attached to it. &lt;&#x2F;li&gt;
&lt;li&gt;There are a few other exotic methods (&lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;boto&#x2F;botocore&#x2F;blob&#x2F;develop&#x2F;botocore&#x2F;credentials.py#L51&quot;&gt;which can be read seen here&lt;&#x2F;a&gt;), such as running a subprocess to get the credentials or hitting another meta data endpoint specific to AWS container services like ECS or Fargate.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span&gt;sys.path.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;insert&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;, os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;LAMBDA_TASK_ROOT&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;])
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# Set &#x2F;var&#x2F;task as site directory so we are able to load all customer pth files
&lt;&#x2F;span&gt;&lt;span&gt;site.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;addsitedir&lt;&#x2F;span&gt;&lt;span&gt;(os.environ[&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;LAMBDA_TASK_ROOT&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;])
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;suppress_init:
&lt;&#x2F;span&gt;&lt;span&gt;    init_handler, request_handler = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;else&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;    init_handler, request_handler = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_get_handlers&lt;&#x2F;span&gt;&lt;span&gt;(handler, mode)
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span&gt;lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_done&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;log_info&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;init complete at epoch &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;{0}&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;format&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#96b5b4;&quot;&gt;round&lt;&#x2F;span&gt;&lt;span&gt;(time.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;time&lt;&#x2F;span&gt;&lt;span&gt;() * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;1000&lt;&#x2F;span&gt;&lt;span&gt;))))
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The next section of bootstrap first inserts the location of our code (look back to the environment variables section, &lt;code&gt;&#x2F;var&#x2F;task&#x2F;&lt;&#x2F;code&gt; is the location of our code and is set to &lt;code&gt;LAMBDA_TASK_ROOT&lt;&#x2F;code&gt;). This ensures that our code is able to be loaded by python. Next we also add the task directory as a &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;site.html#site.addsitedir&quot;&gt;custom site directory&lt;&#x2F;a&gt; which ensures that any custom libraries we&#x27;ve included in our lambda code are also loadable. And finally we optionally call &lt;code&gt;_get_handler&lt;&#x2F;code&gt; depending on the content of &lt;code&gt;suppress_init&lt;&#x2F;code&gt;, which is a flag (&lt;code&gt;bool&lt;&#x2F;code&gt;) given to us from the &lt;code&gt;receive_start&lt;&#x2F;code&gt; function.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I will add that I&#x27;ve never been able to get &lt;code&gt;suppress_init&lt;&#x2F;code&gt; to be &lt;code&gt;True&lt;&#x2F;code&gt;. I&#x27;ve tried different invocation types (sync vs async), calling via straight API or via event source (i.e. Kinesis or API gateway). So if someone is able to work out when&#x2F;if this is set, please let me know.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;The &lt;code&gt;_get_handler&lt;&#x2F;code&gt; function is long and complex to handle a variety of use cases, but I&#x27;ll quickly go over important parts:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;It calls two shared library functions &lt;code&gt;report_user_init_start&lt;&#x2F;code&gt; and &lt;code&gt;report_user_init_end&lt;&#x2F;code&gt; at it&#x27;s start and directly before returning.&lt;&#x2F;li&gt;
&lt;li&gt;In addition to loading the handler function you&#x27;ve specified for you lambda, it also loads a function called &lt;code&gt;init&lt;&#x2F;code&gt; from you handler module if it exists. It is commented in the code that this is maintained for backwards compatibility (and it not mentioned in AWS docs are far as I can find).&lt;&#x2F;li&gt;
&lt;li&gt;Depending on the &lt;code&gt;mode&lt;&#x2F;code&gt; (either &lt;code&gt;http&lt;&#x2F;code&gt; or &lt;code&gt;event&lt;&#x2F;code&gt;) flag, also passed in via &lt;code&gt;receive_start&lt;&#x2F;code&gt;, your handler is either treated as a normal python function or it is treated as a &lt;a href=&quot;https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0333&#x2F;&quot;&gt;WSGI&lt;&#x2F;a&gt; handler. Which is what the &lt;code&gt;wsgi.py&lt;&#x2F;code&gt; module we saw along side &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; is used for. Interestingly again I&#x27;ve never been able to get my lambda to actually have a &lt;code&gt;http&lt;&#x2F;code&gt; mode (used similar tests to the &lt;code&gt;suppress_init&lt;&#x2F;code&gt; flag above), I still haven&#x27;t been able to work out if this is a yet to be unreleased feature or is legacy from when lambda was purely a service for just web requests.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;After doing the initialisation steps the runtime calls &lt;code&gt;report_done&lt;&#x2F;code&gt; to signify that we&#x27;ve finished the setup and are ready to start the actual event handler loop, and well as logging some debug information. And again the &lt;code&gt;log_info&lt;&#x2F;code&gt; command does not output to anywhere us as a user can see, so it is purely for AWS&#x27;s use.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;while &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;True&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;    (invokeid, x_amzn_trace_id, sockfd, credentials, event_body,
&lt;&#x2F;span&gt;&lt;span&gt;      context_objs, invoked_function_arn) = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;wait_for_invoke&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_GLOBAL_AWS_REQUEST_ID &lt;&#x2F;span&gt;&lt;span&gt;= invokeid
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;x_amzn_trace_id != &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;        os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_X_AMZN_TRACE_ID&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;] = x_amzn_trace_id
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;elif &lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_X_AMZN_TRACE_ID&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39; in os.environ:
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;del &lt;&#x2F;span&gt;&lt;span&gt;os.environ[&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;_X_AMZN_TRACE_ID&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;]
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#65737e;&quot;&gt;# If the handler hasn&amp;#39;t been loaded yet, due to init suppression, load it now.
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;request_handler is &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;        init_handler, request_handler = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_get_handlers&lt;&#x2F;span&gt;&lt;span&gt;(handler, mode)
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;run_init_handler&lt;&#x2F;span&gt;&lt;span&gt;(init_handler, invokeid)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;mode == &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;http&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;:
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;handle_http_request&lt;&#x2F;span&gt;&lt;span&gt;(request_handler, invokeid, sockfd)
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;elif &lt;&#x2F;span&gt;&lt;span&gt;mode == &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;event&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;:
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;handle_event_request&lt;&#x2F;span&gt;&lt;span&gt;(request_handler, invokeid, event_body,
&lt;&#x2F;span&gt;&lt;span&gt;                              context_objs, invoked_function_arn)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now at first glance it looks quite complicated. However most of the lines are just either adding Xray trace information or dealing with either the handlers missing or whether to use the &lt;code&gt;event&lt;&#x2F;code&gt; or &lt;code&gt;http&lt;&#x2F;code&gt; event type (again, I&#x27;ve never been able to get lambda to actually use the &lt;code&gt;http&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;So below is what it looks like with the bare minimum.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;while &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;True&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;    (invokeid, x_amzn_trace_id, sockfd, credentials, event_body, context_objs, invoked_function_arn) = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;wait_for_invoke&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;_GLOBAL_AWS_REQUEST_ID &lt;&#x2F;span&gt;&lt;span&gt;= invokeid
&lt;&#x2F;span&gt;&lt;span&gt;    
&lt;&#x2F;span&gt;&lt;span&gt;     &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;handle_event_request&lt;&#x2F;span&gt;&lt;span&gt;(request_handler, invokeid, event_body, context_objs, invoked_function_arn)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Much for straight forward. We get an event. Set our request id and then handle the event.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;wait_for_invoke&lt;&#x2F;span&gt;&lt;span&gt;():
&lt;&#x2F;span&gt;&lt;span&gt;    (invokeid, data_sock, credentials, event_body, context_objs,
&lt;&#x2F;span&gt;&lt;span&gt;     invoked_function_arn, x_amzn_trace_id) = lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;receive_invoke&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;set_environ&lt;&#x2F;span&gt;&lt;span&gt;(credentials)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;(invokeid, x_amzn_trace_id, data_sock, credentials, event_body,
&lt;&#x2F;span&gt;&lt;span&gt;            context_objs, invoked_function_arn)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Wait for invoke is very simple, it just makes a call into the shared library to get the invocation, which includes the event as well as a set of AWS credentials. It then sets the appropriate environment variables so that our function handler has the correct IAM role assigned to our function via the &lt;code&gt;set_environ&lt;&#x2F;code&gt; call.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;handle_event_request&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;request_handler&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;invokeid&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;event_body&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;context_objs&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;                         &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;invoked_function_arn&lt;&#x2F;span&gt;&lt;span&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_user_invoke_start&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    errortype = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;try&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;        client_context = context_objs.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;(&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;client_context&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;)
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;if &lt;&#x2F;span&gt;&lt;span&gt;client_context:
&lt;&#x2F;span&gt;&lt;span&gt;            client_context = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;try_or_raise&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;: json.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;loads&lt;&#x2F;span&gt;&lt;span&gt;(client_context),
&lt;&#x2F;span&gt;&lt;span&gt;                                          &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Unable to parse client context&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;)
&lt;&#x2F;span&gt;&lt;span&gt;        context = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LambdaContext&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, context_objs, client_context,
&lt;&#x2F;span&gt;&lt;span&gt;                                invoked_function_arn)
&lt;&#x2F;span&gt;&lt;span&gt;        json_input = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;try_or_raise&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;: json.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;loads&lt;&#x2F;span&gt;&lt;span&gt;(event_body),
&lt;&#x2F;span&gt;&lt;span&gt;                                  &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;Unable to parse input as json&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;)
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;request_handler&lt;&#x2F;span&gt;&lt;span&gt;(json_input, context)
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;try_or_raise&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;            &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;lambda&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;to_json&lt;&#x2F;span&gt;&lt;span&gt;(result),
&lt;&#x2F;span&gt;&lt;span&gt;            &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;An error occurred during JSON serialization of response&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;)
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;except &lt;&#x2F;span&gt;&lt;span&gt;wsgi.FaultException &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;e:
&lt;&#x2F;span&gt;&lt;span&gt;        lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_fault&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, e.msg, e.except_value, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_xray_fault_helper&lt;&#x2F;span&gt;&lt;span&gt;(&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;LambdaValidationError&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, e.msg, [])
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;make_error&lt;&#x2F;span&gt;&lt;span&gt;(e.msg, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;to_json&lt;&#x2F;span&gt;&lt;span&gt;(result)
&lt;&#x2F;span&gt;&lt;span&gt;        errortype = &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;unhandled&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;except &lt;&#x2F;span&gt;&lt;span&gt;JsonError &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;e:
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_fault_helper&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, e.exc_info, e.msg)
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;to_json&lt;&#x2F;span&gt;&lt;span&gt;(result)
&lt;&#x2F;span&gt;&lt;span&gt;        errortype = &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;unhandled&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;except &lt;&#x2F;span&gt;&lt;span&gt;Exception &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;e:
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_fault_helper&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, sys.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;exc_info&lt;&#x2F;span&gt;&lt;span&gt;(), &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;None&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;        result = &lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;to_json&lt;&#x2F;span&gt;&lt;span&gt;(result)
&lt;&#x2F;span&gt;&lt;span&gt;        errortype = &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;unhandled&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_user_invoke_end&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    lambda_runtime.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;report_done&lt;&#x2F;span&gt;&lt;span&gt;(invokeid, errortype, result)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Again another fairly long function. But most of that is dealing with different error scenarios. Lets go step by step.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;First tell the runtime that the user handler invocation has started via &lt;code&gt;report_user_invoke_start&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Next we parse the event body from json into native python types as well as assembling &lt;a href=&quot;https:&#x2F;&#x2F;docs.aws.amazon.com&#x2F;lambda&#x2F;latest&#x2F;dg&#x2F;python-context-object.html&quot;&gt;the context object.&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We then call the user handler, which is the code we provide to our lambda function.&lt;&#x2F;li&gt;
&lt;li&gt;There is then a few different error branches to deal with various issues that could encounter, from the basics of the handler function throwing an exception to more specific issues like event or response json validation errors.&lt;&#x2F;li&gt;
&lt;li&gt;If any of these errors happens we build a nicely formatted stacktrace via &lt;code&gt;report_fault_helper&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Finally we tell the runtime that we&#x27;ve finished the user code as well as reporting we are done with either the error or the result.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So it has taken a while but we&#x27;ve made our way through the AWS Lambda python runtime. But we&#x27;re not quite done. In face we&#x27;ve only finished the easy bit.&lt;&#x2F;p&gt;
&lt;p&gt;The next stage, I will admit dear reader, took me ~10x the amount of time to work out than everything thus far. Which is mostly my not being familiar with analysing a binary&#x2F;shared library. I suspect that someone more well versed with such analysis would have found it trivial. But what is the point of doing something, if you don&#x27;t learn a new skill along the way. &lt;&#x2F;p&gt;
&lt;h3 id=&quot;sharing-is-caring&quot;&gt;Sharing is caring&lt;&#x2F;h3&gt;
&lt;p&gt;This brings us handily to the analysis of the shared libraries. Now while I think this was the most interesting part of the process, it is very tedious to trace every execution path as well reconstructing what I think the c structs look like. So instead I&#x27;ll walk through a couple of examples, some interesting observations and finally my reconstruction (in python) of the shared library code.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s not get head of ourself and refresh what we already know about the shared libraries and we&#x27;ll start with the one loaded by &lt;code&gt;boostrap.py&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ls &#x2F;var&#x2F;runtime&#x2F;awslambda
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;bootstrap.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;__init__.py
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;runtime.cpython-36m-x86_64-linux-gnu.so
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;wsgi.py
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;runtime.cpython-36m-x86_64-linux-gnu.so&lt;&#x2F;code&gt; is loaded by &lt;code&gt;import runtime&lt;&#x2F;code&gt; in &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt;. The &lt;code&gt;cpython-36m-x86_64-linux-gnu&lt;&#x2F;code&gt; suffix tells us that it a python c extension, which is why python know how to load it and why we are given back native python objects from calls to &lt;code&gt;runtime&lt;&#x2F;code&gt; in &lt;code&gt;boostrap.py&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; lcmd ldd &#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;runtime.cpython-36m-x86_64-linux-gnu.so
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;linux-vdso.so.1&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt;  (0x00007fff66bbb000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libpthread.so.0&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;libpthread.so.0 (0x00007efd7c36c000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libpython3.6m.so.1.0&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;var&#x2F;lang&#x2F;lib&#x2F;libpython3.6m.so.1.0 (0x00007efd7c02d000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;liblambdaio.so&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;var&#x2F;runtime&#x2F;liblambdaio.so (0x00007efd7c79f000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;liblambdaruntime.so&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;var&#x2F;runtime&#x2F;liblambdaruntime.so (0x00007efd7c795000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;liblambdaipc.so&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;var&#x2F;runtime&#x2F;liblambdaipc.so (0x00007efd7c78e000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;liblambdalog.so&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;var&#x2F;runtime&#x2F;liblambdalog.so (0x00007efd7c78b000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libc.so.6&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;libc.so.6 (0x00007efd7bc69000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;&#x2F;lib64&#x2F;ld-linux-x86-64.so.2&lt;&#x2F;span&gt;&lt;span&gt; (0x00007efd7c588000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libdl.so.2&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;libdl.so.2 (0x00007efd7ba65000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libutil.so.1&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;libutil.so.1 (0x00007efd7b862000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;librt.so.1&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;librt.so.1 (0x00007efd7b65a000)
&lt;&#x2F;span&gt;&lt;span&gt;	&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;libm.so.6&lt;&#x2F;span&gt;&lt;span&gt; =&amp;gt; &#x2F;lib64&#x2F;libm.so.6 (0x00007efd7b358000)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If we next look at what the runtime extension is linked against we can confirm that it is linked against libpython3. But it is also linked against some more shared libraries one directory up. &lt;code&gt;liblambdaruntime&lt;&#x2F;code&gt;, &lt;code&gt;liblambdaipc&lt;&#x2F;code&gt;, &lt;code&gt;liblambdaio&lt;&#x2F;code&gt; and &lt;code&gt;liblambdalog&lt;&#x2F;code&gt;.
If we look at how those are linked we get the following dependency graph.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;dependencies.png&quot; alt=&quot;dependencies&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So after copying those shared libraries to our local machine. It is time to break out &lt;a href=&quot;https:&#x2F;&#x2F;binary.ninja&quot;&gt;Binary Ninja&lt;&#x2F;a&gt;. This choice will probably irritate some people, but its price for personal use is hard to argue with. That being said &lt;a href=&quot;https:&#x2F;&#x2F;www.hex-rays.com&#x2F;products&#x2F;ida&#x2F;&quot;&gt;IDA&lt;&#x2F;a&gt; or &lt;a href=&quot;https:&#x2F;&#x2F;www.hopperapp.com&#x2F;&quot;&gt;Hopper&lt;&#x2F;a&gt; would also be fine choices. &lt;&#x2F;p&gt;
&lt;h3 id=&quot;reverse-engineering-for-dummies-me&quot;&gt;Reverse engineering for dummies (me)&lt;&#x2F;h3&gt;
&lt;p&gt;So I am going to summarise what the shared libraries do, but how did I work this out you ask? Well the answer is basically trial and error and banging my head against a wall for months learning assembly and generally being incompetent. So I will show you a few examples of how I reverse engineered the control flow and structure of these shared libraries, but I must warn you that this is almost certainly either wrong or slow or more likely both.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja1.png&quot; alt=&quot;binja1&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Here is an example of the control flow graph generated by binary ninja.
In particular this function called &lt;code&gt;PyInit_runtime&lt;&#x2F;code&gt;, tells us that the function is &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;extending&#x2F;building.html#c.PyInit_modulename&quot;&gt;run when the module is imported.&lt;&#x2F;a&gt;
This also solves the mystery of how initialisation is performed if all we can see in bootstrap.py is the code before. 
If you take a look back at bootstrap.py, we can see that one of the first things it does is import the runtime C extension, therefore this initialisation function is run before almost anything else.&lt;&#x2F;p&gt;
&lt;p&gt;And looking at the control flow it is fairly easy to work out what is going on. It is the same as the following pseudocode:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;if global PY_RUNTIME_RUNNING != 0 {
&lt;&#x2F;span&gt;&lt;span&gt;  error = runtime_init()
&lt;&#x2F;span&gt;&lt;span&gt;  if error != 0 {
&lt;&#x2F;span&gt;&lt;span&gt;    exit()
&lt;&#x2F;span&gt;&lt;span&gt;  } else {
&lt;&#x2F;span&gt;&lt;span&gt;    global PY_RUNTIME_RUNNING = 1
&lt;&#x2F;span&gt;&lt;span&gt;  }
&lt;&#x2F;span&gt;&lt;span&gt;  
&lt;&#x2F;span&gt;&lt;span&gt;  global RUNTIME = runtime
&lt;&#x2F;span&gt;&lt;span&gt;  
&lt;&#x2F;span&gt;&lt;span&gt;  PyModule_Create2()
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Fairly straight forward, and in essence the entire process follows a similar structure, look at the control flow, work out what it is doing and write it out as pseudocode.
So next we would follow the &lt;code&gt;runtime_init&lt;&#x2F;code&gt; function, however it is not in the &lt;code&gt;runtime.cpython&lt;&#x2F;code&gt; module and so we have to jump to &lt;code&gt;liblambdaruntime&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now this one is a bit more complex...&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja2.png&quot; alt=&quot;binja2&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I would like to say I am an amazing hacker that this comes naturally too, however that is entirely not the case.
The AWS engineers were nice enough to compile the code with debug symbols, which is why most of the control flow graphs have reasonable names for things.
But more importantly they are using a very useful error reporting framework that does almost all the reversing for me. 
What do I mean by this? It is easier to just show you.
For example let&#x27;s take a look at this particularly gnarly function.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja3.png&quot; alt=&quot;binja3&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I won&#x27;t cover what it actually does, but the eagle eyed of you will have spotted the error handling branches.
And if we follow them we find the following strings.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja4.png&quot; alt=&quot;binja4&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Which in full are:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;((__runtime-&amp;gt;xray_sock = socket(2, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0))) &amp;gt;= 0
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;inet_aton(xray_address, &amp;amp;address.sin_addr)
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;(connect(__runtime-&amp;gt;xray_sock, (struct sockaddr *) &amp;amp;address, sizeof(address))) == 0
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;src&#x2F;lambda&#x2F;runtime.c&amp;quot;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which gives us a much clearer idea of what is actually going on, we can piece together that it is opening and connecting to a datagram socket at the &lt;code&gt;xray_address&lt;&#x2F;code&gt; and then storing the result in the &lt;code&gt;__runtime&lt;&#x2F;code&gt; struct.&lt;&#x2F;p&gt;
&lt;p&gt;Now the &lt;code&gt;__runtime&lt;&#x2F;code&gt; struct is interesting as it pops up all over the place, and again I&#x27;d like to say I worked out it&#x27;s definition just from reading the assembler, but the answer is far far more tedious. 
You see the RUNTIME global we saw before is actually set to a pointer to this &lt;code&gt;__runtime&lt;&#x2F;code&gt; struct, which means it is accessible from out python code using the cffi module.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;def &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8fa1b3;&quot;&gt;get_native_runtime_struct&lt;&#x2F;span&gt;&lt;span&gt;():
&lt;&#x2F;span&gt;&lt;span&gt;  rt_pointer = ctypes.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;POINTER&lt;&#x2F;span&gt;&lt;span&gt;(ctypes.c_char * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;0x880&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;  dll = ctypes.cdll.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;LoadLibrary&lt;&#x2F;span&gt;&lt;span&gt;(
&lt;&#x2F;span&gt;&lt;span&gt;      &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;runtime.cpython-36m-x86_64-linux-gnu.so&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;)
&lt;&#x2F;span&gt;&lt;span&gt;  rt = rt_pointer.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;in_dll&lt;&#x2F;span&gt;&lt;span&gt;(dll, &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;__runtime&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;)
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;try&lt;&#x2F;span&gt;&lt;span&gt;:
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;rt.contents
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;except &lt;&#x2F;span&gt;&lt;span&gt;ValueError:
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;NullPointer&lt;&#x2F;span&gt;&lt;span&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;All we are doing is dumping out the 2176 bytes (0x880) at the &lt;code&gt;__runtime&lt;&#x2F;code&gt; location from the shared library. 
Why 2176? Because of this part of the &lt;code&gt;runtime_init&lt;&#x2F;code&gt; function.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja5.png&quot; alt=&quot;binja5&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;And if we look at the result of the above code, we get a bunch of nonsense like this.&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;bytearray(
&lt;&#x2F;span&gt;&lt;span&gt;    b&amp;#39;#\x00\x00\x00*\x00\x00\x00\x00\x00\x00\x00\x00\x00arn:aws:lambda:ap-southeast-2:12345678910:function:pyinject
&lt;&#x2F;span&gt;&lt;span&gt;    \x00\x7f\x00\x00\xd0\xa0&#x2F;\xd5\xf9\x7f\x00\x00\xa5\xd9Z\xc1k\x98\xe0l\xb0\x96&#x2F;\xd5\xf9\x7f\x00\x00\xc0\x7f\xe7\xdc\xf9
&lt;&#x2F;span&gt;&lt;span&gt;    \x7f\x00\x00\x88\x9by7\xff\xda(\xa0XX&#x2F;\xd5\xf9\x7f\x00\x00\xe0\x7f\xe7\xdc\xf9\x7f\x00\x00\xac\x1a9\xf6\x08E\xa7\xd4
&lt;&#x2F;span&gt;&lt;span&gt;    \xa0X&#x2F;\xd5\xf9\x7f\x00\x00\x00\x80\xe7\xdc\xf9\x7f\x00\x00\x81-\x95\x06\x06\xde\xa9\xbd\xe8X&#x2F;\xd5\xf9\x7f\x00\x00
&lt;&#x2F;span&gt;&lt;span&gt;    \x80\xe7\xdc\xf9\x7f\x00\x00\xb0~6\xe1\x9d\xee\x8e\x0f\xf8f&#x2F;\xd5\xf9\x7f\x00\x00\xe0\x7f\xe7\xdc\xf9\x7f\x00\x00\xcc
&lt;&#x2F;span&gt;&lt;span&gt;    ... and so on)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Which has some recognisable strings in it. So with a combination of the patience and frustration I was able to work out the runtime struct looks like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;class &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ebcb8b;&quot;&gt;Runtime&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;PStruct&lt;&#x2F;span&gt;&lt;span style=&quot;color:#eff1f5;&quot;&gt;):
&lt;&#x2F;span&gt;&lt;span&gt;    _fields_ = [
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;ctrl_sock&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_int),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;console_sock&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_int),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;xray_sock&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_int),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;needs_debug_logs&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_int),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;function_arn&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_char * &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d08770;&quot;&gt;512&lt;&#x2F;span&gt;&lt;span&gt;),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;deadline_ns&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_uint64),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;shared_mem&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;POINTER&lt;&#x2F;span&gt;&lt;span&gt;(SharedMem)),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;pre_load_time_ns&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_uint64),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;post_load_time_ns&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_uint64),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;wait_start_time_ns&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_uint64),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;wait_end_time_ns&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_uint64),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;max_stall_time_ms&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_size_t),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;is_initialized&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_bool),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;init_start_time&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, timeval),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;init_end_time&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, timeval),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;invoke_start_time&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, timeval),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;is_traced&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_bool),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;reported_xray_exception&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, ctypes.c_bool),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;init_xray_context&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, XrayContext),
&lt;&#x2F;span&gt;&lt;span&gt;        (&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;xray_context&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;, XrayContext)
&lt;&#x2F;span&gt;&lt;span&gt;        ]
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And how do I know the names of the fields you ask? Well again if you look carefully you will see the &lt;code&gt;xray_sock&lt;&#x2F;code&gt; field from the debug messages we found before. So all of theme were pulled from the debug messages, and the types were identified via trial and error and the help of the code in &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;blob&#x2F;master&#x2F;container&#x2F;inject&#x2F;runtime_types.py#L12&quot;&gt;PStruct&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Which has a nice printing function so you can see if our guessed types are actually matching the types in the real struct. 
For example it would print the out the following for the above defined Runtime struct, with the byte offsets helpfully annotated.&lt;&#x2F;p&gt;
&lt;p&gt;So once the size of the struct matched the offsets, I knew I had the correct definition. (As well as just some common sense things i.e. file descriptors being ints)&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#2b303b;color:#c0c5ce;&quot;&gt;&lt;code&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    0x0 ctrl_sock: 21,
&lt;&#x2F;span&gt;&lt;span&gt;    0x4 console_sock: 28,
&lt;&#x2F;span&gt;&lt;span&gt;    0x8 xray_sock: 0,
&lt;&#x2F;span&gt;&lt;span&gt;    0xc needs_debug_logs: 0,
&lt;&#x2F;span&gt;&lt;span&gt;    0x10 function_arn: b&amp;#39;arn:aws:lambda:ap-southeast-2:12345678910:function:pyinject&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;    0x210 deadline_ns: 2660013665248,
&lt;&#x2F;span&gt;&lt;span&gt;    0x218 shared_mem: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 event_body_len: 2,
&lt;&#x2F;span&gt;&lt;span&gt;        0x4 debug_log_len: 0,
&lt;&#x2F;span&gt;&lt;span&gt;        0x8 event_body: b&amp;#39;{}&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0x60006c debug_logs: b&amp;#39;&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0x6192a4 response_body_len: 0},
&lt;&#x2F;span&gt;&lt;span&gt;    0x220 pre_load_time_ns: 2656844548537,
&lt;&#x2F;span&gt;&lt;span&gt;    0x228 post_load_time_ns: 2656946702375,
&lt;&#x2F;span&gt;&lt;span&gt;    0x230 wait_start_time_ns: 2657008317187,
&lt;&#x2F;span&gt;&lt;span&gt;    0x238 wait_end_time_ns: 2657008350855,
&lt;&#x2F;span&gt;&lt;span&gt;    0x240 max_stall_time_ms: 0,
&lt;&#x2F;span&gt;&lt;span&gt;    0x248 is_initialized: True,
&lt;&#x2F;span&gt;&lt;span&gt;    0x249 init_start_time: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 tv_sec: 1527519386,
&lt;&#x2F;span&gt;&lt;span&gt;        0x8 tv_usec: 491078},
&lt;&#x2F;span&gt;&lt;span&gt;    0x259 init_end_time: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 tv_sec: 1527519386,
&lt;&#x2F;span&gt;&lt;span&gt;        0x8 tv_usec: 495631},
&lt;&#x2F;span&gt;&lt;span&gt;    0x269 invoke_start_time: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 tv_sec: 140114522192048,
&lt;&#x2F;span&gt;&lt;span&gt;        0x8 tv_usec: 140114651686080},
&lt;&#x2F;span&gt;&lt;span&gt;    0x279 is_traced: False,
&lt;&#x2F;span&gt;&lt;span&gt;    0x27a reported_xray_exception: False,
&lt;&#x2F;span&gt;&lt;span&gt;    0x27b init_xray_context: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 trace_id: b&amp;#39;&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0xff is_sampled: False,
&lt;&#x2F;span&gt;&lt;span&gt;        0x100 parent_id: b&amp;#39;446d6e0975296e18&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0x1ff lambda_id: b&amp;#39;&amp;#39;},
&lt;&#x2F;span&gt;&lt;span&gt;    0x579 xray_context: {
&lt;&#x2F;span&gt;&lt;span&gt;        0x0 trace_id: b&amp;#39;1-5b0c1899-3bfaf18e732c0be2465110a4&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0xff is_sampled: False,
&lt;&#x2F;span&gt;&lt;span&gt;        0x100 parent_id: b&amp;#39;2625bdd20f4e3600&amp;#39;,
&lt;&#x2F;span&gt;&lt;span&gt;        0x1ff lambda_id: b&amp;#39;&amp;#39;}
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;br&#x2F;&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;And that is all I am going to cover in how the actual reverse engineering was done, as it consisted entirely of those steps over and over again.&lt;&#x2F;p&gt;
&lt;p&gt;In terms of &lt;strong&gt;what&lt;&#x2F;strong&gt; each of the shared library files does, I&#x27;ll cover it on broad strokes now.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;runtime-cpython&quot;&gt;runtime.cpython...&lt;&#x2F;h4&gt;
&lt;p&gt;This shared library does very little other than to delegate functionality to the other shared libraries.&lt;&#x2F;p&gt;
&lt;p&gt;This makes sense as it allows for code sharing between the different language runtimes if you keep the shim for your individual language as small as possible.
Though one interesting thing is that it has some sort of spinlock on the length of the result, which I think is how they are coordinating writes to the shared memory struct.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja6.png&quot; alt=&quot;binja6&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Oh right the shared memory struct, the one from the pointer above in the &lt;code&gt;__runtime&lt;&#x2F;code&gt; struct.&lt;&#x2F;p&gt;
&lt;p&gt;So this one took an embarrassingly long time and many re-reading of linux documentation to work out what the heck was going on.
I&#x27;d reccomend you just jump straight to the &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;blob&#x2F;master&#x2F;container&#x2F;inject&#x2F;pyruntime.py#L121&quot;&gt;&lt;code&gt;pyruntime.py&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; file to see what it is doing.&lt;&#x2F;p&gt;
&lt;p&gt;But the gist is that a file descriptor is passed into the lambda function, which is them memory mapped into the process&#x27;s address space, before being closed.&lt;&#x2F;p&gt;
&lt;p&gt;The trick being that is an anonymous memory map, it has no backing file, so once it is closed you have to remember the address returned from the mmap call.
This block of mapped memory is how AWS send events to the lambda function and how events are returned.
Why they couldn&#x27;t just use Unix socket? I don&#x27;t know.
But that is the way they chose to do it.&lt;&#x2F;p&gt;
&lt;p&gt;Anyway back to the spinlock. I think they are using the &lt;code&gt;response_body_len&lt;&#x2F;code&gt; as a multiprocess lock to coordinate writes to the shared memory. What is more interesting is that this takes place in &lt;code&gt;runtime.cpython&lt;&#x2F;code&gt;. Which means that all the other runtimes have to manually implement this lock in their shims. Which all of them do as far as I can tell, all except golang that is. There might be better guarantees around memory writes in golang that I am not aware of, but just something interesting. &lt;&#x2F;p&gt;
&lt;p&gt;Oh by the way I did disassembly, decompile, dump etc all the other language runtimes for cross referencing and general interest, however that is a whole other blog post in itself. But I will cover the more interesting pieces in the future efforts section.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;liblambdaruntime&quot;&gt;liblambdaruntime&lt;&#x2F;h4&gt;
&lt;p&gt;This is where the meat of the work happens.
It holds the initialisation logic as well as all the logic around send and receiving administration commands via the various Unix sockets we found earlier.
It essentially has analogs of all the runtime functions we observed in the &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; walkthrough.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja7.png&quot; alt=&quot;binja7&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;liblambdaipc&quot;&gt;liblambdaipc&lt;&#x2F;h4&gt;
&lt;p&gt;This shared library contains utility functions for IPC communication. The runtime uses Unix sockets to send and receive commands to the AWS host system. These commands need to be serialized&#x2F;de-serialized symmetrically on both ends, so I expected this library is also on the host system.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja8.png&quot; alt=&quot;binja8&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;liblambdalog&quot;&gt;liblambdalog&lt;&#x2F;h4&gt;
&lt;p&gt;This library has some helper function for logging to stdout and the Lambda shared log buffer. Included in the shared memory that is used to send the event and result to and from the function is a region for storing debug logs. These logs are also written to standard out simultaneously by the functions below.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja9.png&quot; alt=&quot;binja9&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h4 id=&quot;liblambdaio&quot;&gt;liblambdaio&lt;&#x2F;h4&gt;
&lt;p&gt;A very simple shared library, it just has some helper functions for synchronised writing to file descriptors.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;binja10.png&quot; alt=&quot;binja10&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pyruntime&quot;&gt;PyRuntime&lt;&#x2F;h3&gt;
&lt;p&gt;Once all of that was worked out, reversed and translated into python we are left with the code in my repo &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;blob&#x2F;master&#x2F;container&#x2F;inject&#x2F;pyruntime.py&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It doesn&#x27;t match 1-1 with all the shared libraries and how their functionality is separated, however it follows the majority of code paths. (with some important caveats covered in the future efforts section.) But more importantly it works. How do I know this? Let&#x27;s find out.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;wrestling-control&quot;&gt;Wrestling control&lt;&#x2F;h4&gt;
&lt;p&gt;So how do you test your new shiny runtime if &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; is run before our code is invoked. It&#x27;s all in the environment. The environment variables that is.&lt;&#x2F;p&gt;
&lt;p&gt;AWS are kind enough to let us set the environment variables for our Lambda functions.
More importantly these environment variables are set &lt;strong&gt;before&lt;&#x2F;strong&gt; the AWS runtime is handed control. 
I.e. they are set when the container is started, not by the runtime.&lt;&#x2F;p&gt;
&lt;p&gt;The key insight is to realise this gives us a way to control how &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; is executed. The cpython interpreter has many flags that can be &lt;a href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;using&#x2F;cmdline.html#environment-variables&quot;&gt;controlled by environment variables&lt;&#x2F;a&gt;, in particular we are interested in &lt;code&gt;PYTHONPATH&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This controls where, and in what order, python looks, when it&#x27;s loading modules.&lt;&#x2F;p&gt;
&lt;p&gt;So if we for example, have two directories with a python module each called &#x27;foo.py&#x27;.&lt;&#x2F;p&gt;
&lt;p&gt;And we add those directories to our &lt;code&gt;PYTHONPATH&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;And we then try to &lt;code&gt;import foo&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;The directory that is first in the path will have it&#x27;s module loaded first.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s take another look at the &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; imports.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;python&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-python &quot;&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;from &lt;&#x2F;span&gt;&lt;span&gt;__future__ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;print_function
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;decimal
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;imp
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;json
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;logging
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;os
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;site
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;socket
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;sys
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;time
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;traceback
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;runtime &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;as &lt;&#x2F;span&gt;&lt;span&gt;lambda_runtime
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#b48ead;&quot;&gt;import &lt;&#x2F;span&gt;&lt;span&gt;wsgi
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So the first thing it loads after the &lt;code&gt;__future__&lt;&#x2F;code&gt; compatibility line is &lt;code&gt;decimal&lt;&#x2F;code&gt;. If we were to put a &lt;code&gt;decimal.py&lt;&#x2F;code&gt; in the &lt;code&gt;PYTHONPATH&lt;&#x2F;code&gt; it will take precedence of the built in decimal module. And so this is example what we would do is.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;set the &lt;code&gt;PYTHONPATH&lt;&#x2F;code&gt; environment variable to &lt;code&gt;&#x2F;var&#x2F;task&#x2F;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;place a &lt;code&gt;decimal.py&lt;&#x2F;code&gt; file in the root of our Lambda function code.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;And now we have our code executing, before the lambda &lt;code&gt;runtime.cpython&lt;&#x2F;code&gt; is loaded.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;decimal.py&lt;&#x2F;code&gt; for my custom runtime can be found here. &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;blob&#x2F;master&#x2F;container&#x2F;decimal.py&quot;&gt;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This file then calls &lt;code&gt;execve&lt;&#x2F;code&gt; with our own slightly modified &lt;code&gt;bootstrap.py&lt;&#x2F;code&gt; thus replacing the process with our own code. And so we have native control in our Lambda container.&lt;&#x2F;p&gt;
&lt;p&gt;As is seen by running the lambda function. &lt;code&gt;current_proc&lt;&#x2F;code&gt; is the result of &lt;code&gt;ps 1&lt;&#x2F;code&gt; which if you remember used to be &lt;code&gt;&#x2F;var&#x2F;runtime&#x2F;awslambda&#x2F;boostrap.py&lt;&#x2F;code&gt;, yet now it is our custom runtime.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#2b303b;color:#c0c5ce;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt; .&#x2F;run.sh
&lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;working&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; true,
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;current_proc&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#bf616a;&quot;&gt;: &lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a3be8c;&quot;&gt;&#x2F;var&#x2F;lang&#x2F;bin&#x2F;python3.6 &#x2F;var&#x2F;task&#x2F;inject&#x2F;bootstrap.py&lt;&#x2F;span&gt;&lt;span&gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Now there is a bit of a problem with me telling this. You see AWS could very easily block this avenue by restricting what environment variables you can set. And so can remove my access at any time. I hope they don&#x27;t, but I also would understand if they wanted to nip this in the bud before anyone sees it, since it would effectively make an internal API, a public once if people start using it (even if it is unsupported.).&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;so-what&quot;&gt;So what?&lt;&#x2F;h3&gt;
&lt;p&gt;So if you looked at the above repo, you will have noticed that my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Posnet&#x2F;pylambda&#x2F;blob&#x2F;master&#x2F;container&#x2F;inject&#x2F;pyruntime.py&quot;&gt;pyruntime.py&lt;&#x2F;a&gt; is in fact written in python.&lt;&#x2F;p&gt;
&lt;p&gt;Why go to all this trouble to replace fast c code with slow python. Especially since Lambda &lt;strong&gt;already&lt;&#x2F;strong&gt; supports python?!&lt;&#x2F;p&gt;
&lt;p&gt;Well this was mainly for my own interest, so that was enough for me. However for the rest of you, it does mean you are now free to use the &lt;code&gt;pyruntime&lt;&#x2F;code&gt; as template implementation. &lt;&#x2F;p&gt;
&lt;p&gt;There is no reason you couldn&#x27;t rewrite it in C++, or Rust, or even Golang (yes I know it is natively supported but you could write your own runtime to get rid of that pesky RPC, that the AWS version uses.).&lt;&#x2F;p&gt;
&lt;p&gt;So that concludes a multi-month long investigation of how AWS have implemented their Lambda runtime.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;future-efforts-or-i-am-lazy-and-tired-of-writing&quot;&gt;Future efforts (Or I am lazy and tired of writing)&lt;&#x2F;h2&gt;
&lt;p&gt;Now there are a bunch of open questions I&#x27;d like to answer however this blog is already too long so I&#x27;ll leave them for a future time. (Even though I have answers to a few of them.)&lt;&#x2F;p&gt;
&lt;h3 id=&quot;containers-and-completeness&quot;&gt;Containers and completeness.&lt;&#x2F;h3&gt;
&lt;p&gt;As demonstrated by the copious &lt;code&gt;TODO&lt;&#x2F;code&gt;s in the pyruntime, I am not yet done replicating 100% of the functionality. The basics work, however there are still many code paths yet unexplored. For example there are whole swaths of code for handling AWS X-Ray reporting from the runtime that I haven&#x27;t touched. Similarly those helpful error messages which I used as cheat sheets in my reversing efforts also provide important debug info to the AWS Lambda team which no longer are being logged. &lt;&#x2F;p&gt;
&lt;p&gt;However my next task, before even finishing the rest of the runtime is to implement the other side of the runtime. And by other side I mean the AWS host side of the lambda function. This is a whole project in of itself, and which I will undoubtedly procrastinate doing.&lt;&#x2F;p&gt;
&lt;p&gt;Luckily I found the amazing &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Fewbytes&#x2F;rubber-docker&quot;&gt;rubber-docker&lt;&#x2F;a&gt; project. Which I have worked out is the perfect base for my host implementation. As well as being a fantastic tutorial for anyone interested in containers and how they actually work.&lt;&#x2F;p&gt;
&lt;p&gt;Once that is done, it will be much easier to work out if my runtime is behaving correctly since I will be able to run the AWS lambda shared libraries locally and make sure my version is sending identical command and logging identical logs as the official one. This will let me verify that my implementation is correct.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;please-be-a-good-citizen&quot;&gt;Please be a good citizen&lt;&#x2F;h4&gt;
&lt;p&gt;So since this reference implementation is not complete, it is likely to fail in unexpected and opaque ways, which will be both confusing to you as well as the AWS Lambda team, so I ask you to be careful with your experimentation and please don&#x27;t try to break things. And for the love of god do not use this in production for any reason, only pain and miserly lies ahead for those that do.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;polyglottal&quot;&gt;Polyglottal&lt;&#x2F;h3&gt;
&lt;p&gt;The other big task is to go over the other runtimes. No I didn&#x27;t forget about them.The other runtimes use the same shared libraries as the python ones, though how they talk to it varies.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The Node.js uses gyp and a shim like python to proxy function calls to &lt;code&gt;liblambdaruntime&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Java uses native methods to talk to &lt;code&gt;liblambdaruntime&lt;&#x2F;code&gt; directly.&lt;&#x2F;li&gt;
&lt;li&gt;Golang is a weird one. Because golang doesn&#x27;t support shared libraries, in order to allow cgo to link against the runtime without revealing the source code, AWS have opted to write a daemon that links against the shared libs and then have that talk to your handler over golang&#x27;s native RPC interface.&lt;&#x2F;li&gt;
&lt;li&gt;C#, I haven&#x27;t looked at this one, but I assume it just uses the C# runtime&#x27;s native calling like java&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I am sure there is useful information that can be used to make the reversing of the runtime easier and more complete by looking at these other language runtimes. However that will have to be a topic for another time.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;elephant-in-the-env-var&quot;&gt;Elephant in the env var&lt;&#x2F;h3&gt;
&lt;p&gt;So I mentioned before that AWS can remove our entrypoint by restricting the environment variables we can set.
If they do so, the shared library runtime will run, before our code is execution in the main Lambda event loop.&lt;&#x2F;p&gt;
&lt;p&gt;We could take control again here if it wasn&#x27;t for the fact that after memory mapping the shared buffer, the runtime then closes those file descriptors. &lt;&#x2F;p&gt;
&lt;p&gt;This is a problem since memory maps do not survice &lt;code&gt;exec&lt;&#x2F;code&gt; and we cannot re-open the fd since it was passed to us, already open, on &lt;code&gt;fork&lt;&#x2F;code&gt; and we don&#x27;t have access to any actual file. Which once closed cannot be re-opened. This means we can&#x27;t then &lt;code&gt;exec&lt;&#x2F;code&gt; ourselves without loosing the the memory map.&lt;&#x2F;p&gt;
&lt;p&gt;We can still wrestle control of the runtime and never return to AWS&#x27;s event loop. So while we will then almost have full control, we are still in the address space of the original process. Which could reduce the overhead of Lambda invocations (though it won&#x27;t save you money since it is already very easy to get below the 100ms minimum charge) but it isn&#x27;t going to help with cold starts for example.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;discussion&quot;&gt;Discussion&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17187226&quot;&gt;Hacker News&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;aws&#x2F;comments&#x2F;8n8amt&#x2F;reverse_engineering_aws_lambda&#x2F;&quot;&gt;Reddit&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Hello Website</title>
            <pubDate>Mon, 12 Jun 2017 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/first-post/</link>
            <guid>https://www.denialof.services/first-post/</guid>
            <description>&lt;p&gt;I finally got arround to setting up my website.&lt;&#x2F;p&gt;
&lt;p&gt;s3 ✔&lt;&#x2F;p&gt;
&lt;p&gt;Cloudfront ✔&lt;&#x2F;p&gt;
&lt;p&gt;Route53	✔&lt;&#x2F;p&gt;
</description>
        </item>
        <item>
            <title>Guidelines</title>
            <pubDate>Sat, 01 Jan 2000 00:00:00 +0000</pubDate>
            <link>https://www.denialof.services/guidelines/</link>
            <guid>https://www.denialof.services/guidelines/</guid>
            <description>&lt;h2 id=&quot;life&quot;&gt;Life&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;The Iron Rule: Treat others less powerful than you however you like.&lt;&#x2F;p&gt;
&lt;p&gt;The Silver Rule: Treat others as you’d like to be treated.&lt;&#x2F;p&gt;
&lt;p&gt;The Golden Rule: Treat others as they’d like to be treated.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Dennis E. Taylor, Heaven&#x27;s River &lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Entities should not be multiplied without necessity&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Occam&#x27;s Razor&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Never attribute to malice that which is adequately explained by stupidity&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Hanlon&#x27;s Razor&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;THEN TAKE THE UNIVERSE AND GRIND IT DOWN TO THE FINEST POWDER AND SIEVE IT THROUGH THE FINEST SIEVE AND THEN SHOW ME ONE ATOM OF JUSTICE, ONE MOLECULE OF MERCY. AND YET YOU ACT AS IF THERE IS SOME IDEAL ORDER IN THE WORLD, AS IF THERE IS SOME...SOME RIGHTNESS IN THE UNIVERSE BY WHICH IT MAY BE JUDGED.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Terry Pratchett, Hogfather&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;When it comes to things that separate you from the ground, every dollar spent is worth it. This applies especially to shoes, socks, chairs and beds.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;―  Alec Posney&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;www.ted.com&#x2F;talks&#x2F;randy_pausch_really_achieving_your_childhood_dreams&quot;&gt;&amp;quot;Really achieving your childhood dreams&amp;quot; - Randy Pausch&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;work&quot;&gt;Work&lt;&#x2F;h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;The purpose of a system is what it does.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Stafford Beer&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Unfortunately, most warning systems do not warn us that they can no longer warn us.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Charles Perrow, Normal Accidents&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;If there are two or more ways to do something and one of those results in a catastrophe, then someone will do it that way.&amp;quot; (Murphy&#x27;s Law)&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Edward A. Murphy Jnr.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;That which can be asserted without evidence, can be dismissed without evidence.&amp;quot; &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;― Christopher Hitchens (Hitchens&#x27;s Razor)&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;https:&#x2F;&#x2F;spacecraft.ssl.umd.edu&#x2F;akins_laws.html&quot;&gt;Akin&#x27;s Laws of Spacecraft Design&lt;&#x2F;a&gt; - Applicable to almost any area of engineering.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;http:&#x2F;&#x2F;www.catb.org&#x2F;jargon&#x2F;html&#x2F;&quot;&gt;Jargon File&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</description>
        </item>
    </channel>
</rss>
