<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Clay Smith on Medium]]></title>
        <description><![CDATA[Stories by Clay Smith on Medium]]></description>
        <link>https://medium.com/@smithclay?source=rss-911fff6ff5ef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RftzG8FozOjLfJi9.JPG</url>
            <title>Stories by Clay Smith on Medium</title>
            <link>https://medium.com/@smithclay?source=rss-911fff6ff5ef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 19:15:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@smithclay/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rebooting San Francisco royalty: Emperor Norton meets GenAI]]></title>
            <link>https://medium.com/clog/rebooting-san-francisco-royalty-emperor-norton-meets-genai-b28a5874e1a7?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/b28a5874e1a7</guid>
            <category><![CDATA[history]]></category>
            <category><![CDATA[emperor-norton]]></category>
            <category><![CDATA[san-francisco]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 14:56:45 GMT</pubDate>
            <atom:updated>2024-07-24T15:06:18.050Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Oyez, oyez! We, Norton I, Emperor of America and Chief Wrangler of Cantankerous Seagulls, do hereby proclaim: Our Royal persona shall be reborn in the realm of thinking machines! All citizens must converse with Our digital doppelgänger or face a tax of 37 pineapples.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLnC7GFt1FjaSwrKndmLUw.png" /><figcaption>San Francisco Panorama circa 1880</figcaption></figure><p>The genteel alleys of Jackson Square north of San Francisco’s Transamerica Pyramid are full of boutique venture capital firms, design studios, and the occasional Michelin-starred restaurant. As one of the few neighborhoods not obliterated by the 1906 earthquake, it also has a direct connection to the city’s Barbary Coast origins. If you take a historical walking tour, you’ll hear about the gold and silver rushes, financial panics, political corruption, violent gangs of Australian convicts, and an eccentric named <a href="https://en.wikipedia.org/wiki/Emperor_Norton">Joshua Norton</a> who proclaimed himself Emperor of the United States and Protector of Mexico.</p><p>The most recent San Francisco boom cycle involves generative artificial intelligence, not precious metals in the Sierras. The peculiar mix of local culture, technology, and money is the same. Developers are writing code on the same street where Emperor Norton wrote a proclamation with the then-absurd idea of a bridge across the Bay. He was the original mascot, progressive, oddball, and minor celebrity who helped generations of locals reflect on what kind of a place San Francisco was or could be.</p><p>Last year, I decided to use generative AI to recreate Norton’s voice and have it engage with people on social media. I was interested in how an AI model of Norton, which I’ll refer to as the Emperor Bot, could make us more creative. Much of what is written about AI seems to be about civilization-ending scenarios or startup pitches for new ways to summarize your emails. I wanted to know if generative AI could help people reflect on the past… and possibly laugh.</p><h4><strong>Building an Emperor Bot that challenges injustice</strong></h4><p>The first thing I had to do was build the bot, which was the most fun I’ve had on a technical project in a long time. How it works is straightforward, even for a non-programmer: you instruct a large language model (LLM), like OpenAI’s GPT-4, to reply as Emperor Norton. This instruction is called the prompt.</p><p>Some facts about Norton have been incorporated into the base LLM models. The result is cutting-edge technology approximating how to speak in the voice of someone from the 19th century. After I made dozens of small adjustments to the prompt — it was difficult to get the replies concise — here’s the bot’s reply to a tweet about seagulls and a locally famous Taco Bell:</p><blockquote>Emperor Norton I has decreed that all seagulls must be removed from Pacifica &amp; its environs. The Board of Supervisors must award damages to the owners of the desecrated Cathedral of Taco Bell.</blockquote><p>The reply captures three things that are essential to the historical Norton: it challenges injustice (albeit of a Taco Bell), holds politicians accountable, and does so with the authority of someone with absolute political power.</p><p>Here’s another reply to a tweet from a local supervisor proposing renovation of some crumbling piers that doesn’t hit the mark:</p><blockquote>We decree that Piers 30–32 in San Francisco shall be rebuilt as a mixed-use development with public recreation, retail, office, and housing!</blockquote><p>The pro-development tweet was it seemed inauthentic in the worst possible way. It didn’t capture the historical voice. It was like seeing an ad for breakfast cereal featuring an Emperor Norton proclamation on whole grains. I wanted to understand if this was truly a limitation of the current models, or something that could be improved.</p><h4><strong>Finding Norton’s authentic voice in the LLM</strong></h4><p>One of the issues with recreating Norton’s voice is that, while everything he wrote is in the public domain, there is a thin historical record for someone who continues to be famous in the modern era. The proclamations he published were short, and no journal or diary survived. With the help of local historians I became more familiar with gold rush era San Francisco. John Lumea of the<a href="https://emperornortontrust.org/"> Emperor Norton Trust</a>, the world’s foremost expert on Norton, sent me several helpful emails, and Taryn Edwards of the <a href="https://www.milibrary.org/">Mechanics’ Institute</a> (where the real Norton was a member) shared a reading list with a warning: <em>San Francisco history is rife with lore and legend</em>.</p><p>I can never know Norton’s views on the correct amount to tip at restaurants, but did know he was always against corruption and wanted to keep politicians accountable… to the point of calling for Congress to be abolished. Using more AI, I generated a map of the themes and topics Norton wrote about and hoped it would guide better responses.</p><p>For example, Norton had a proclamation that referred to sailing ships — but his writing on the ships thematically touched on justice, authority, responsibility and safety. When he wrote about being refused entrance to an event by “snobs in charge of the door” — the map pointed to his concerns around the abuse of power and social hierarchies.</p><p>Instead of parroting or sounding like a shill, the bot’s replies seemed to improve with the new context. Here’s the reply to the news of a local brewery closing:</p><blockquote>Great Scott! Anchor Brewing, a city gem, faces peril? We’ll rally, oh we will! Workers, I stand in solidarity with you! Citizens, let us preserve our city’s heritage!</blockquote><p>It was around this time a controversial local billionaire changed policies and most bots, including the Emperor Bot, were kicked off Twitter.</p><h4><strong>BlueSky Social, hackerspaces and vegetables</strong></h4><p>Elon Musk kicked the bots off Twitter because he wanted money for the type of access the bots needed to post, which was previously free. This resulted in the Emperor Bot moving to the newer social network <a href="https://bsky.app/profile/emperornorton.bsky.social">BlueSky</a>.</p><p>Despite being a friendlier and invite-only version of Twitter at the time, I was concerned what might happen. Despite profile disclosures and a prominent robot icon, my impression is that most people assumed the text was written by a cosplaying San Francisco history nerd pretending to be a digital version of Norton.</p><p>Non-public tests with the bot commenting on trending topics went badly. The bot never generated outright offensive content, but anything related to politics was inflammatory. Even positive replies, like support for the Hollywood writers’ strike, were problematic. People striking for reasons related to losing their livelihoods over AI-generated content do not want a supportive yet eccentric 19th century bot to join the conversation. The fully-automated social media version was never released, so I reviewed replies and posted the unaltered text every few days.</p><p>The most engaging conversations with the bot were in private channels on Discord, the popular chat app. A local hackerspace added it to their AI channel and started interacting with it. Using the latest tricks being spread around the LLM space, bot replies seemed to improve when I added an “therapy” mode where the bot would articulate its sensations, fears and desires before replying.</p><p>Here’s the bot’s inner monologue for replying to something related political corruption:</p><blockquote>Sensations: A harsh, sneering laughter rings in my ears, leaving an unpleasant taste in my mouth.</blockquote><blockquote>Fears: Anarchy and corruption taking over my beloved city.</blockquote><blockquote>Desires: To enact justice and maintain the order of my realm.</blockquote><p>Somebody also asked the bot what vegetable it found the most threatening.</p><blockquote>I would say it is the artichoke. Its sharp exterior might be seen as a symbol of uprising, but in truth, it’s the tastiest rebellion I’ve ever faced.</blockquote><h4><strong>A folk hero emerges on BlueSky Social</strong></h4><p>The bot was finding a certain groove on Discord, but on BlueSky it was limited to replys related to a very small number of topics: mostly pets and Norton himself. I was surprised how culturally relevant Norton, who died in 1880, is to modern-day San Francisco and how deep that appreciation and fandom goes. An award-winning author was one of the first followers.</p><p>My impression is that Norton is a folk hero on social media or, depending on who you ask, the world’s first crypto bro. (He printed his own money and passed it off as legal tender.) People imply they would love to vote for him in the current election. He’s also considered a minor saint in a belief system that started in 1960s Berkeley called <a href="https://en.wikipedia.org/wiki/Discordianism">Discordianism</a> (no relation to the app Discord).</p><p>The most liked posts from the bot, after some trial and error, were those that acted as a kind of promoter for San Francisco and the historical Norton. Anything else tended to annoy or confuse people, like John Adams showing up on Instagram and liking your vacation photo. When someone skeeted (that’s BlueSky for tweet) that Norton was cool and they wished he could save everyone now, it replied:</p><blockquote>Indeed, time unceasingly marches forward. While I can’t step forth in flesh, my philosophies persist. Lead with benevolence, act with authenticity.</blockquote><p>In another instance, the bot replied to a post memorializing Norton with a familiar sounding phrase: “death is but a door, time a window.” It’s a quote from the villain in the 1989 movie <em>Ghostbusters II</em>… a 16th century historical figure that comes back to life in an evil painting.</p><h4><strong>What are the chances of the Emperor Bot taking over the world?</strong></h4><p>The 1906 earthquake destroyed much of Norton’s San Francisco. The murkiness of the late 19th century also means that it’s easier for every generation to repurpose Norton to fit their mood and anxieties. In present day San Francisco and the United States: there are plenty of issues to choose from.</p><p>Of course, one of the largest local conversations in technology is the promise and perils of generative AI itself.</p><p>It’s not hard to imagine these sorts of bots finding a place in educational settings or museums to make history more interactive and conversational, at least for well-liked and popular historical figures. The bot would be an excellent companion in a self-guided walking tour of the Emperor’s old neighborhood.</p><p>There’s also the obvious danger of these bots on social media, which has been written about at length in many different places. My assessment is the risk of the Emperor Bot causing global conflict or taking over governments as a digital Emperor is effectively zero. However, it’s hard to think of any scenario where more advanced gen AI bots will improve the overall quality of conversation in the near-term on social media.</p><p>There has been an enormous amount of investment from major companies to make sure the output of LLMs is inoffensive and not harmful, but that is changing as individuals and groups create their own models. Using a collection of scanned 19th century newspapers, I started on an experiment with fine-tuning the bot to make it sound more like actual writers from the 1880s. That was paused once I realized that I did not want my bot to pick up on the views that existed in the vast majority of late 19th-century American newspapers.</p><h4><strong>Norton, generative AI, and a way forward</strong></h4><p>Joshua Norton is buried in Colma, the cemetery city just south of San Francisco. There’s a marble headstone that says <em>Norton I Emperor</em> in large letters. E Clampus Vitus, a 19th-century fraternal organization (sometimes called in the press a “historical drinking society”) throws a party honoring his legacy once a year on “Norton Day” at his gravesite. There’s a convenient Irish bar a short stroll away.</p><p>My theory on why Norton still has a large number of admirers who toast him is because, in his own chaotic and eccentric way, he is remembered for fighting against injustice. He also was an immigrant to San Francisco who made and lost a fortune but still figured out a way to get free lunches and had a popular newspaper column for twenty years.</p><p>Generative AI will never be able to capture the full context, intricacies, and contradictions of the human Norton but it can be strange and unexpected. Despite the peril of thousands of trolling bots taking over social media, in the right context this technology can be fun and creative — without taking over the world or your job.</p><p>Uncertainty hangs over the air right now for both AI and San Francisco. There are plenty of doom loop scenarios being discussed for both. Economically, the success or failure of generative AI will also have a direct impact on The City for years to come. The open question for local entrepreneurs depositing checks from venture capitalists is what happens next. At one extreme: collapse from malevolent AI. Another direction is the mediocrity of bots that make life worse via annoying assistants that get in the way.</p><p>A happy outcome would be technology — and a city — where people are able to be thoughtful, explore new ideas, and maybe have fun while holding those in power accountable. It might also get a little weird and off-putting at times. We should, in other words, take more inspiration from Emperor Norton.</p><p><em>Thanks to John Lumea of the Emperor Norton Trust, Tayrn Edwards of the San Francisco Mechanics Institute, the weekend staff at The San Francisco History Center, the Prelinger Library, The Ancient and Honorable Order of E Clampus Vitus, the Misalignment Museum, and various adherents of Discordianism active on BlueSky and Discord.</em></p><p><em>You can follow the Emperor Bot at </em><a href="https://bsky.app/profile/emperornorton.bsky.social"><em>https://bsky.app/profile/emperornorton.bsky.social</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b28a5874e1a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/rebooting-san-francisco-royalty-emperor-norton-meets-genai-b28a5874e1a7">Rebooting San Francisco royalty: Emperor Norton meets GenAI</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My neural net turned into an Apple zealot after training it on mid-1990s WIRED issues]]></title>
            <link>https://medium.com/clog/my-neural-net-turned-into-an-apple-zealot-after-training-it-on-mid-1990s-wired-issues-dd07df5fc9ac?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd07df5fc9ac</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[wired]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 13:31:01 GMT</pubDate>
            <atom:updated>2019-07-02T16:02:20.538Z</atom:updated>
            <content:encoded><![CDATA[<h3>My neural net turned into an Apple zealot after training it on mid-90s WIRED issues</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*MV3CFoPXFNieMtAmHfBzew.png" /><figcaption>Generated text using OpenAI’s <a href="https://openai.com/blog/better-language-models/">GPT-2 </a>and OCR text from mid-1990s WIRED issues</figcaption></figure><p>I trained a bleeding-edge machine learning (ML) model with a dozen issues of WIRED magazine from the mid-1990s and things got weird. The new model started generating a unique blend of 90s-era techno-optimism, product advertisements for microprocessors and gaming systems that never existed, odd interviews with tech luminaries and… a profound love for all things Apple.</p><p>There’s a popular ML technique going around where people generate text using neural networks based on different source materials. The technology isn’t advanced enough to make us think that a sensible person actually wrote the generated text—a serious problem we’re going to have to deal with—but it’s often good enough to produce bizarre statements that are funny in context.</p><p>I first tried it around <a href="https://medium.com/clog/using-ai-to-generate-an-ico-white-paper-d328f26577f3">two years ago to generate an ICO whitepaper</a> and there have been many other developers, data scientists, and researchers who have continued to explore. <a href="https://aiweirdness.com/aboutme">Janelle Shane’s posts on this subject</a> are wonderful and inspired this work. In the past two years, the effectiveness of the models have significantly improved.</p><p>This post is about what happened when I wanted to train one of the newer models going around (<a href="https://openai.com/">OpenAI’s</a> GPT-2) with mid-1990s WIRED magazine issues.</p><h4>WIRED, Nostalgia and Machine Learning</h4><p>I grew up reading WIRED magazine, and I’m not immune to the nostalgia for the period of the 1990s when the internet and personal computers were a new and amazing thing for many people in the United States.</p><p>Generating text from the model is surprisingly addictive—with a click of a button, it’s like reading something a WIRED journalist might write after not sleeping for three days.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dT1Xoxn_UesQcpnZ2_y_OA.png" /></figure><p>There is also a strange blend of marketing and journalism is impacted by the training data—WIRED issues in the 90s, after all, had plenty of print ads. As a result you get serious-sounding statements about history mixed with product marketing speak:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*MRMxUNJjri33TuHdsUeXtQ.png" /></figure><p>Sometimes this veers off into editorialization. After a quote around how you can get the latest PowerBook “when it’s available” (which every tech company would write in announcements if they could get away with it), this paragraph ends with something that sounds like a melody:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*hWcqId3l-SgVdJ3fIPdzFg.png" /></figure><p>When it comes to technology luminaries of the mid-1990s, even seemingly critical quotes of Jobs end up making him look good:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*xwyX_GIO6lFeOtGMrr3qUw.png" /></figure><p>Bill Gates, in contrast, basically has to plead that Microsoft isn’t actually in trouble when seeking an ambitious target of “download hits”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*XOZmjNKiRNTk3zQZzD-7RQ.png" /></figure><h4>The machine learning hype is real?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*KCP6IU0uWk9GrwZHp2HC5Q.png" /><figcaption>The hype, man, it’s real.</figcaption></figure><p>This started as a quick AI experiment to see how text generation models were advancing. From start to finish (including training time), it took only about two hours before text started coming out, including some text that wouldn’t look out of place in an experimental poetry journal.</p><p>While it was fun and fascinating to see what was generated, it also doesn’t seem unrealistic that more advanced versions of the model would probably be good enough to generate entirely convincing WIRED articles that seemed like they were written in the 90s. That’s disturbing for anyone who reads digitized historical sources of anything on the internet.</p><p>The creator of the GPT-2 model, OpenAI, <a href="https://openai.com/blog/better-language-models/#update">has committed to working with research and governmental institutions on the societal impact of widespread use of models like this</a>, including an advanced version of GPT-2 that hasn’t been publicly released yet.</p><p>As a creative tool, however, my experiments with WIRED and neural networks were unexpectedly inspiring. Strange alternate histories, quotes, bizarre products, and koan-like statements around the future emerged.</p><p>My deep concern for the future of these language models is combined with a desire to read the first few chapters of a book featuring Larry Ellison, his wife FmmL, and Denny Dallas. Maybe they’re all Apple fans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*vRa0PhaxK1OrvpC-brN3ww.png" /><figcaption>The plot of 2025’s bestselling tech thriller?</figcaption></figure><p><em>Thanks for reading! Might get around to turning this model into some kind of chat bot in the next few weeks. Find me on twitter: </em><a href="https://twitter.com/smithclay"><em>@smithclay</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd07df5fc9ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/my-neural-net-turned-into-an-apple-zealot-after-training-it-on-mid-1990s-wired-issues-dd07df5fc9ac">My neural net turned into an Apple zealot after training it on mid-1990s WIRED issues</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TCP/IP over Amazon Cloudwatch Logs]]></title>
            <link>https://medium.com/clog/tcp-ip-over-amazon-cloudwatch-logs-c1cf08f2296c?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1cf08f2296c</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Thu, 02 May 2019 13:31:00 GMT</pubDate>
            <atom:updated>2019-05-02T13:31:00.864Z</atom:updated>
            <content:encoded><![CDATA[<h4>Running network services inside AWS Lambda Functions</h4><p>You can’t ping an AWS Lambda function. You can’t SSH into a running function <a href="https://medium.com/clog/ssh-ing-into-your-aws-lambda-functions-c940cebf7646">without reverse tunneling</a>. You would never run nginx or Rails inside of a function because there’s little point — accepting an inbound TCP connection on a port like a Docker container isn’t supported by function-as-a-service (FaaS) platforms. It is possible, however, to write your own userspace networking stack and do what you want with it —including using Amazon Cloudwatch Logs (or even AWS Lambda tags) as the data link layer.</p><p>This post is about implementing TCP/IP over Amazon Cloudwatch Logs using Go, which enables you to access network services running inside of AWS Lambda functions.</p><p>It’s slow and not very useful, but it was a fun way to learn more about Linux networking and using AWS services in a way that might horrify some AWS engineering teams. I’m calling this proof-of-concept “<strong>Richard Linklayer”</strong> and <a href="https://github.com/smithclay/rlinklayer">published the full Github code today.</a></p><h3>A Serverless Architecture Darkly</h3><p>This experiment was the escalation of:</p><ul><li>Trying to run progressively <a href="https://medium.com/clog/running-selenium-and-headless-chrome-on-aws-lambda-fb350458e4df">stranger</a> <a href="https://medium.com/clog/ssh-ing-into-your-aws-lambda-functions-c940cebf7646">things</a> in AWS Lambda.</li><li>Interest in exploring <a href="https://github.com/google/netstack">netstack</a>, an IPv4/IPv6 userland networking stack from Google.</li><li>Hearing contradictory and confusing things from some clients and engineering teams around different limitations of serverless functions.</li></ul><p>I attempted to check off all three of those things using Go. With netstack, it’s possible to do some exotic things with networking in unexpected places, no kernel hacking (i.e. writing C code) required. Any Go program with read and write access to reliable-ish bi-directional communication channel — like logs, tags or <a href="https://en.wikipedia.org/wiki/IP_over_Avian_Carriers">carrier pigeon</a> — can implement full in-process TCP/IP networking. There are many AWS services that meet this criteria.</p><p>Network tunneling is not a new idea, but inside the AWS Lambda execution environment a userspace solution is needed because it’s not possible to change routing tables, modify network interfaces, or change OS-level networking (unlike container-based network overlays or service meshes).</p><p>Running in a standard Go process, Richard Linklayer tunnels IP packets over Amazon Cloudwatch Log Streams that follow a special naming convention — the stream and log group names are just MAC addresses. Using a tun or tap interface, I can bridge my AWS Lambda network endpoints to my local development machine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sYCn3BhpTon89Nt8" /><figcaption>High-level architecture of Richard Linklayer where a Linux host communicates with a TCP network service running inside of an AWS Lambda function. The process polls Amazon Cloudwatch for new inbound packets.</figcaption></figure><p>This design ignores normal AWS Lambda event-driven patterns for processing inbound packets and sending outbound packets —only a single instance of a function starts, reads and writes from Cloudwatch using polling, then processes packets until it times out. There is only one instance of a function running a unique network service running at any given time, and it can only accept network connections for up to 15 minutes, the maximum timeout of an AWS Lambda function in early 2019.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/0*wPTklPyIuEI3LoXT" /><figcaption>Lifecycle of an AWS Lambda function that accepts inbound TCP requests via Cloudwatch. Don’t do this.</figcaption></figure><p>When you put it all together, the result is that you can ping a Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/0*2wJktNatuiupDEbN" /><figcaption>Pinging an AWS Lambda function on Mac OS X via a Linux container. It’s kind of slow but remember everything is running over Amazon Cloudwatch.</figcaption></figure><p>The underlying implementation over Amazon Cloudwatch is at <a href="https://en.wikipedia.org/wiki/Data_link_layer">layer 2,</a> so it’s reading and writing ethernet packets delivered to MAC addresses. MAC address discovery happens using <a href="https://en.wikipedia.org/wiki/Address_Resolution_Protocol">ARP</a> with a special-purpose log stream that acts as a “broadcast address” for the entire network.</p><p>Since it supports anything that runs over TCP, you can also cURL a node.js HTTP server running inside of a function, or anything else that listens on a TCP port. This server returns some text after a few seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*pVFK-lYuXlqFkNXn" /><figcaption>Making an HTTP request to a node.js server running inside of an AWS Lambda function.</figcaption></figure><p>The latency means that this would likely never work for anything production-level, but TCP is resilient enough to handle the slow connection.</p><p>We have full transparency into the network traffic since it’s just data inside of log streams. It looks like this, which is the stream of IPv4 traffic from <em>74:74:74:74:74</em> to <em>42:42:42:42:42</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*biGVnazegJoe0ZG8" /><figcaption>Layer 2 Observability? Traffic from one MAC address to another that uses Cloudwatch as the channel.</figcaption></figure><p>An example on how to get this working with a <a href="https://github.com/smithclay/rlinklayer/tree/master/examples">simple network running an HTTP server is on Github</a>. While not described in this post, there is also an additional link layer that uses AWS Lambda function tags as a transport that has slightly better performance results.</p><h3>Dazed and Lambfused</h3><p>There’s a lot of interesting open-source networking projects in the container space right now: <a href="https://github.com/envoyproxy/envoy">Envoy</a>, <a href="https://linkerd.io/">Linkerd</a>, and <a href="https://github.com/cilium/cilium">Cilium</a> to name a few. With support for custom AWS Lambda runtimes released at re:Invent in 2018, I’m curious how emerging control or data planes are going to impact serverless functions beyond additional language support and monitoring and security solutions.</p><p>Beyond that, there’s a few interesting ideas to explore beyond this proof-of-concept, including:</p><ul><li>UDP services (DNS over AWS Lambda, anyone?)</li><li>Any kind of performance optimizations (everything is based on polling APIs and could be tuned)</li><li>Exploration of other link layer transports in AWS (DynamoDB streams? SNS? SQS? S3?)</li></ul><p><a href="https://github.com/smithclay/rlinklayer">Pull requests and ideas welcome.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1cf08f2296c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/tcp-ip-over-amazon-cloudwatch-logs-c1cf08f2296c">TCP/IP over Amazon Cloudwatch Logs</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using AI to generate an ICO white paper]]></title>
            <link>https://medium.com/clog/using-ai-to-generate-an-ico-white-paper-d328f26577f3?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/d328f26577f3</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ico]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Thu, 16 Nov 2017 13:56:01 GMT</pubDate>
            <atom:updated>2017-11-16T23:49:46.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rH9Lh2RZprmbUp4FXM6U0w.png" /><figcaption>The white paper generated using a recurrent neural network.</figcaption></figure><p>With ICOs, or token sales of cryptocurrencies, <a href="https://hackernoon.com/insider-reflections-on-the-ico-bubble-6304c4d25ed8">having reportedly raised $2.3 billion in 2017,</a> the time seemed right to use AI to generate a fake ICO white paper programmatically using a <a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/">recurrent neural network</a> (RNN) in the cloud.</p><p>I’ve titled it “RNN-Coin” <a href="https://github.com/smithclay/char-embeddings-ml-engine/blob/master/whitepaper.pdf">and have published the full white paper here (pdf)</a>.</p><p>RNNs are a machine learning technique that have frequently and hilariously been used to generate arbitrary text from text-based training data. Some of my favorite examples are generating <a href="https://medium.com/@hondanhon/i-trained-a-neural-net-to-generate-british-placenames-9460e907e4e9">new British town names</a> or <a href="https://github.com/nihitx/game-of-thrones-">a Game of Thrones</a> book. However, unlike most town names or the work of George R.R. Martin, there are plenty of people that claim that ICO whitepapers are mostly incomprehensible anyway. This post shares some the technical background and some of the excerpts from the paper (it’s painful to read in full).</p><h4>Building the model</h4><p>Using <a href="https://www.tensorflow.org/">Tensorflow</a>, <a href="https://cloud.google.com/ml-engine/">Google Cloud ML engine</a>, <a href="https://github.com/mfclarke/char-embeddings-ml-engine">and a modified RNN example I came across on Github from Maximilian Clarke</a>, I created a model using a GPU-powered cloud training job that ran for a few hours (my MacBook Pro was too slow and RNNs are resource-intensive to train). The trained model could then output text that eerily echoed many ICO white papers.</p><p>For the published white paper, I generated around 2,000 characters at a time from 40-character sentence seeds I pulled from real white papers (<a href="https://bitcoin.org/bitcoin.pdf">like the Bitcoin white paper</a>). I then manually organized the output into sections — formatted in LaTeX for full white paper legitimacy, of course.</p><p>One of the first outputs became the basis of the white paper abstract:</p><blockquote>A purely peer-to-peer version of the company system with the price of the system to develop and the contract agent servers and the price of the system of the system which is a simple decentralized system which is the contract to provide the contract […] can be considered as a result of the blockchain.</blockquote><p>The algorithm created peer-to-peer, blockchain-backed alternative to corporate structure! It’s just a simple decentralized system. The price is still developing, however.</p><h4>The local revolution of experience is here!</h4><p>RNNs have been described by<a href="http://karpathy.github.io/2015/05/21/rnn-effectiveness/"> some people as “magical” or “uncanny”</a> and after going through this exercise I agree. There are points in the white paper that sound perfectly reasonable — and even decent marketing. What millennial, including myself, <em>wouldn’t </em>want to be part of “the local revolution of experience”?</p><p>It often generates language constructions that don’t sound natural. This could probably be tuned further by trying cleaner training data and different model parameters. Yet strange-sounding sentences also have gems:</p><blockquote>This is the highest commitment wallet that a confident of money for medical currencies of the project in the initiative instruments of the project is the farmer of the cost of the system.</blockquote><p>A “highest commitment wallet” might be a reassuring concept for an ICO investor in medical currencies.</p><h4>“A pledge to the smart token” (and having fun with ML)</h4><blockquote>The first social advance is a problem for control of the platform.</blockquote><p>I don’t see RNNs replacing real white paper writers or creating ICOs, but the experience of building and training fairly complex machine learning models that were previously the exclusive domain of academics and researchers does seem to be getting much easier for the average developer.</p><p>Much of the code for sample tensorflow projects using different ML techniques is freely available on Github and it seems cloud providers are now <a href="https://aws.amazon.com/ec2/elastic-gpus/">racing to rent GPUs</a> to developers for model training purposes. I think as more tensorflow projects get shared the potential for collaboration also goes up: if a real AI/ML researcher comes across this post, p<a href="https://github.com/smithclay/char-embeddings-ml-engine">ull requests are welcome</a> to refine the model.</p><p>There is much speculation and uncertainty around the future of ICOs, but it also seems like there has never been a better time to generate fake ICO white papers with AI.</p><p><a href="https://github.com/smithclay/char-embeddings-ml-engine/raw/master/whitepaper.pdf">The full paper is available for download here (pdf).</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d328f26577f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/using-ai-to-generate-an-ico-white-paper-d328f26577f3">Using AI to generate an ICO white paper</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing an Ethereum smart contract from the 19th century]]></title>
            <link>https://medium.com/clog/writing-an-ethereum-smart-contract-from-the-19th-century-c9572790f185?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9572790f185</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[19th-century]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Tue, 17 Oct 2017 15:26:30 GMT</pubDate>
            <atom:updated>2017-10-28T04:10:29.680Z</atom:updated>
            <content:encoded><![CDATA[<p>Thought it’d be fun to explore blockchain hype and write a simple <a href="https://www.coindesk.com/information/ethereum-smart-contracts-work/">Ethereum smart contract</a> based on an short story from the 19th century.</p><p>In middle school, I remember reading Robert Louis Stevenson’s <a href="https://en.wikipedia.org/wiki/The_Bottle_Imp"><strong><em>The Bottle Imp</em></strong></a>, written in 1891. The story describes the the struggles of a person who buys a magic bottle from an elderly man who lives in a “fine house on a hill” in San Francisco. It grants unlimited wishes with certain <em>evil</em> conditions: you can’t sell it to anyone else for more than you paid for it and if you can’t find a willing buyer before you expire <strong>you’re doomed</strong>. You also have to pay in real minted coins: no paper money is allowed so there’s some physical limit to how cheaply you can sell it.</p><p>Remembering this story while reading about the blockchain, the obvious thing to do was attempt to implement it as an <a href="https://ethereum.org/">Ethereum</a> smart contract on a sunny Sunday afternoon. <a href="https://github.com/smithclay/etherimp">I’ve published the code on Github here</a>.</p><h4>My attempt at sounding like I know about what I’m talking about about with blockchain</h4><p>This was my first attempt and building a ÐApp (<a href="https://ethereum.stackexchange.com/questions/383/what-is-a-dapp">decentralized app</a>). I feel like including this diagram of distributed networks from a 1962 academic paper gives this post some additional gravitas and is completely self-explanatory on the benefits of decentralized applications, the nature of distributed ledgers, and inherent security considerations of applications built using this technology:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*tbaizJv1spbNUhG2.png" /><figcaption><a href="http://pages.cs.wisc.edu/~akella/CS740/F08/740-Papers/Bar64.pdf">On Distributed Communications Networks</a>, Paul Baran (1962)</figcaption></figure><h4>Now that we have a full and complete understanding of Ethereum and distributed applications, how does the contract work?</h4><blockquote>As for why I sell so cheap, I must explain to you there is a peculiarity about the bottle.<br><a href="http://gutenberg.spiegel.de/buch/the-bottle-imp-4357/1"> — The Bottle Imp</a></blockquote><p>In the process of writing this smart contract, I was terrified. Outside of the usual pains of figuring out how to write, deploy, and build things using a completely new toolchain (the <a href="https://solidity.readthedocs.io/en/develop/">Solidity</a> language, <a href="https://github.com/ethereumjs/testrpc">testrpc</a>, and the <a href="https://github.com/ethereum/wiki/wiki/JavaScript-API">web3</a> APIs), it was unsettling to read though a <a href="https://github.com/ConsenSys/smart-contract-best-practices">popular resource on potential security vulnerabilities from ConsenSys</a>.</p><p>The contract I wrote (my first) does only one trivial thing by design: <em>transfer ownership of the (virtual) bottle if they pay less than the previous owner</em>.</p><p>However, from best practices I found it seems clear that production-grade smart contracts need to go through a lot of testing and analysis. Specifically, it’s a good idea to:</p><ul><li>Really understand the Solidity language and know the danger of external calls, transfer calls, and <a href="https://en.wikipedia.org/wiki/Reentrancy_(computing)">reentrancy</a> vulnerabilities.</li><li>Integrate rate-limiting and “pause” functionality if things go wrong.</li><li>Use static analysis and linting to catch vulnerabilities.</li><li>Explore different patterns to upgrade your contract as new vulnerabilities are discovered.</li><li>Start a bug bounty program to thoroughly test it (with rewards to those who find issues) before the contract goes live on the main ethereum network. Maybe hire some consultants for auditing purposes, too (they were all over my Google search results for Solidity development questions).</li><li>Consider using frameworks like <a href="https://github.com/trufflesuite/truffle">truffle</a> or <a href="https://github.com/OpenZeppelin/zeppelin-solidity">OpenZepplin</a> when you realize you’re probably doing it wrong.</li></ul><p>Attempting to, uh, “implement” some of those best practices over a couple hours, <a href="https://github.com/smithclay/etherimp/blob/master/contracts/EtherImp.sol#L24">I came up with this code for the key logic in the contract to transfer the bottle</a>. If the price is less than the price the previous owner paid and it’s non transferred back to the same account— the bottle has a new owner and the price paid is transferred back the previous owner:</p><pre>function buyBottle() payable public {<br>  // Conditions<br>  require(msg.sender != currentOwner);<br>  require(msg.value &gt; 0);<br>  require(msg.value &lt; lastPricePaid);</pre><pre>  // Effects<br>  previousOwner = currentOwner;<br>  currentOwner = msg.sender;<br>  lastPricePaid = msg.value;<br>  LogTransfer(previousOwner, currentOwner, lastPricePaid);</pre><pre>  // Interactions<br>  // *Security alert (correction on October 27, 2017):*<br>  // This implementation isn&#39;t safe! See GitHub and comments.<br>  previousOwner.transfer(msg.value);<br>}</pre><p>The “conditions”, “effects” and “interactions” comments are only for reassurance based on a <a href="https://ethereum.stackexchange.com/questions/19341/address-send-vs-address-transfer-best-practice-usage">solidity question I read on StackOverflow</a>. Otherwise, I’m conservatively ~40% sure it works without a major structural flaw or security vulnerability.</p><p><strong>Like the original short story, there’s ultimately a loser in this contract: if the value paid is 1 wei — the smallest allowable unit in Ethereum, you’re stuck with ownership of this smart contract forever.</strong></p><p>After some local testing and <a href="https://www.rinkeby.io/">trying it out on the Rinkeby test network</a>, decided it was time to ship it.</p><h4>It’s live on the main Ethereum network, beware!</h4><blockquote>“This is the bottle,” said the man; and, when Keawe laughed, “You do not believe me?” he added. “Try, then, for yourself. See if you can break it.”<br><a href="http://gutenberg.spiegel.de/buch/the-bottle-imp-4357/1"> — The Bottle Imp</a></blockquote><p>The contract/virtual bottle has been published to the main Ethereum network and is able to be transferred to anyone who wants it— as long as you pay less than the previous account did. I’m curious to see how long it takes for the value to get down to 1 wei and what happens (if anything).</p><p>To kick things off, <em>I’ve started the price of the contract at the going rate of a of a typical sandwich in the Financial District of San Francisco: 0.05 ETH</em> (~16 USD).</p><p>If you’re new to Ethereum, I’d recommend downloading the <a href="https://github.com/ethereum/mist/releases">Mist browser</a> or <a href="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en">Metamask extension</a> and then visiting the following address: <a href="https://wallet.ethereum.org/account/0x9fcd683584173c5df0ee47852f5592f68ed72a0c">https://wallet.ethereum.org/account/0x9fcd683584173c5df0ee47852f5592f68ed72a0c</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qChPwEBf0lLVbFIfjP40uQ.png" /><figcaption>The contract visualized in the Mist browser. The “buy bottle” function transfers ownership.</figcaption></figure><p>Feedback and vulnerability assessments welcome in the comments, on <a href="https://twitter.com/smithclay">twitter</a>, <a href="https://github.com/smithclay/EtherImp">or on the Github project page</a>.</p><p>If you’re new to all this can also recommend <a href="https://www.coinbase.com/what-is-ethereum?locale=en-US">Coinbase’s general introduction to Ethereum (and how it’s different from Bitcoin)</a>. For getting started with development, the <a href="https://www.reddit.com/r/ethereum/">Reddit community</a> was useful too.</p><p>Regardless of where the blockchain hype goes — and who ends up stuck with the smart contract I created when they buy inevitably buy it for 1 wei — it was really interesting to learn more about the process of building and testing smart contracts. Last word, as it does in <strong><em>The Bottle Imp</em></strong>, goes to the boatswain:</p><blockquote>“I don’t value any of your talk,” replied the boatswain. “You thought I was a flat; now you see I’m not; and there’s an end. If you won’t have a swallow of the rum, I’ll have one myself. Here’s your health, and good-night to you!”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9572790f185" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/writing-an-ethereum-smart-contract-from-the-19th-century-c9572790f185">Writing an Ethereum smart contract from the 19th century</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Selenium and Headless Chrome on AWS Lambda]]></title>
            <link>https://medium.com/clog/running-selenium-and-headless-chrome-on-aws-lambda-fb350458e4df?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb350458e4df</guid>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[selenium]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 16:59:46 GMT</pubDate>
            <atom:updated>2018-03-13T04:04:47.176Z</atom:updated>
            <content:encoded><![CDATA[<p>There seems to be a small community of developers building interesting browser things on AWS Lambda with Headless Chrome.</p><p>Around a month ago, I was also prototyping a small <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> project that enabled running <a href="http://www.seleniumhq.org/projects/webdriver/">Selenium Webdriver</a> with <a href="https://developers.google.com/web/updates/2017/04/headless-chrome">Headless Chrome</a> inside a Lambda function called <a href="https://github.com/smithclay/lambdium">lambdium</a> (disclaimer: no relation to laudanum).</p><p>I wanted to share the general architecture of the app and some things I learned while building it to help any other developers wanting to give serverless and Headless Chrome a try.</p><p>There’s also great post <a href="https://medium.com/@kensoh/chromeless-chrominator-chromy-navalia-lambdium-ghostjs-autogcd-ef34bcd26907">by Ken Soh for an overview</a> of other projects experimenting with Headless Chrome and AWS Lambda. <a href="https://news.ycombinator.com/item?id=14859084">The comments in a recent Hacker News post about the Chromeless project</a> are worth a read, too.</p><h4>Binaries not included</h4><p>In brief, AWS Lambda is just an event-driven Linux container on EC2 with some <a href="https://www.kernel.org/doc/Documentation/cgroup-v1/freezer-subsystem.txt">special cgroup sauce</a> — <a href="https://speakerdeck.com/smithclay/faas-measurement-fundamentals">see my Gluecon talk for more on that</a>. Because of that, it’s perfectly acceptable to run almost any non-privileged process you want inside Lambda as you would in a container. You just invoke a 64-bit Linux binary that doesn’t require special privileges using something like Node.js’s <a href="https://nodejs.org/api/child_process.html">child_process module</a> or <a href="https://docs.python.org/2/library/subprocess.html">Python’s subprocess library</a> in code in the main function handler.</p><p>Complex Linux binaries like chromium, though, need lots of shared libraries and assume a couple things about the Linux environment that don’t play perfectly with Lambda. <a href="https://medium.com/@marco.luethy?source=post_header_lockup">Marco Lüthy</a> came to the rescue in early March and figured out how exactly to get the chromium binary working. His <a href="https://github.com/adieuadieu/serverless-chrome">serverless-chrome</a> project is now the reference implementation for many projects, including <a href="https://github.com/graphcool/chromeless">chromeless</a> and lambdium.</p><p>With the ability to run Headless Chrome in AWS Lambda, I was curious if I could get <a href="http://www.seleniumhq.org/projects/webdriver/">Selenium</a> tests to run using <a href="https://sites.google.com/a/chromium.org/chromedriver/home">ChromeDriver</a>. Then, using one of the <a href="http://docs.seleniumhq.org/download/">many Selenium client libraries</a>, I could run pre-existing tests in different languages. After many iterations of copying shared libraries around — I <a href="https://gist.github.com/smithclay/7852bfdbf565ba6fe0601b0e2d01b56b">detailed the general recipe for getting untested binaries working on Github</a> — ChromeDriver was able to run and interact with Headless Chrome inside a Lambda function. With ChromeDriver running, I just had to connect a Selenium client library to it.</p><h4>Finally: running Selenium tests</h4><p>By going through the process above, I was able to get ChromeDriver and Headless Chrome running inside an AWS Lambda function — barely making it under the compressed 50mb size limit for functions (the Chrome binary is around 80% of this).</p><p>Surprisingly, running the Selenium tests using the Node.js <a href="https://www.npmjs.com/package/selenium-webdriver">selenium-webdriver</a> module ended up being possible with just a few changes to the default options:</p><ol><li>There are a <a href="https://github.com/smithclay/lambdium/blob/master/lib/chromium.js#L12">bunch of Headless Chrome-specific command line options you need to specify</a>.</li><li>You have to tell Selenium where to find the Headless Chrome binary (because it’s in AWS Lambda, it’s not in the PATH).</li></ol><p>With that done, there was a <a href="https://github.com/smithclay/lambdium/issues">mostly working</a> Selenium Webdriver session with Headless Chrome running in AWS Lambda ready to go. The output of a script that visits Google.com and checks the title looks like this in AWS Cloudwatch(again, not much to see because it’s headless after all):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*8R-I5RmiPeFz1Ozy2cKuOQ.png" /><figcaption>Output of a Selenium script running in Headless Chrome on AWS Lambda</figcaption></figure><p>According to the <a href="https://s3.amazonaws.com/lambda-tools/pricing-calculator.html">AWS Lambda calculator</a>, if I ran that same function 1,000 more times, my monthly bill (<em>not</em> including the free tier of the service) would come to $0.04. I increased the function memory to 1152mb—running Chrome takes a lot more than the default memory size in AWS Lambda.</p><h4>Project setup and known issues</h4><p>The prototype project, which initially tried to design as “framework-less” and as boing as possible (it’s just regular Node.js, a Makefile , and some shell-scripts), is<a href="https://github.com/smithclay/lambdium"> up on Github</a>. It shouldn’t be too hard to port to, say, Python, C# or Java (all AWS Lambda-supported languages). As of early January 2018, I migrated the project to use <a href="https://github.com/awslabs/aws-sam-local">AWS SAM Local</a> and in March 2018 <a href="https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:156280089524:applications~lambdium">I ported it the AWS Serverless Application Repository (one click install!)</a>.</p><p>I’m still working on a new branch that should improve startup times, but that’s a subject for another post.</p><h4>Will Headless Chrome shake things up in the browser QA/test world?</h4><p>The duo of Headless Chrome and AWS Lambda seems like it has a real possibility to shake up automated browser testing — due in no small part to how cost effective serverless is for low-volume traffic like occasional browser testing in QA. With the generous Lambda free tier, you could probably run low-volume browser tests on AWS infrastructure for free.</p><p>Also, there’s no reason why Headless Chrome couldn’t also work on other serverless compute platforms, and there seems to be plenty of interest <a href="https://github.com/yukinying/chrome-headless-browser-docker">running it in Docker as well</a>. I give it 6 months, max, before someone writes some sort of Kubernetes cluster that runs Headless Chrome at scale.</p><p>Think it’s a pretty fun time to be hacking on serverless compute platforms or even containers in general — especially with the recent release of Headless Chrome and the cool things that are going to be built with it.</p><p>Pull requests and questions welcome. Also highly recommend you check out the <a href="https://medium.com/@kensoh/chromeless-chrominator-chromy-navalia-lambdium-ghostjs-autogcd-ef34bcd26907">other projects in Ken Soh’s post</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb350458e4df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/running-selenium-and-headless-chrome-on-aws-lambda-fb350458e4df">Running Selenium and Headless Chrome on AWS Lambda</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSH-ing into your AWS Lambda Functions]]></title>
            <link>https://medium.com/clog/ssh-ing-into-your-aws-lambda-functions-c940cebf7646?source=rss-911fff6ff5ef------2</link>
            <guid isPermaLink="false">https://medium.com/p/c940cebf7646</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Clay Smith]]></dc:creator>
            <pubDate>Tue, 02 May 2017 13:41:03 GMT</pubDate>
            <atom:updated>2017-05-10T16:12:23.014Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Finally proof that serverless has servers?</blockquote><p>I spoke at <a href="https://dotscale.io/">dotScale</a> in Paris last week <a href="https://speakerdeck.com/smithclay/searching-for-the-server-in-serverless">about some stuff I’ve been working on to learn more about Function-as-a-Service (FaaS) performance</a>.</p><p>While my talk was mostly about cold starts, function warming, and understanding the internal architecture of FaaS, lots of people were curious how I was able to SSH into a running AWS Lambda function. This post describes how to turn Lambda functions into a short-lived Linux servers with some help from <a href="https://godoc.org/golang.org/x/crypto/ssh">Go’s SSH crypto libraries</a>.</p><h4>Adventures in missing dependencies</h4><p>Many popular FaaS services are built on Linux containers—Azure seems to use IIS voodoo I don’t understand. From an serverless app developer perspective, you write a handler function in a supported language that’s bundled with its dependencies. When a predefined event like an HTTP request occurs, the handler function is invoked inside the container and your code runs (or has an error, or times out).</p><p>Because the environment is just a container, you’re allowed to execute binaries using standard language features like <a href="https://nodejs.org/api/child_process.html">exec() in node.js</a> or <a href="https://docs.python.org/2/library/subprocess.html">python subprocess</a>. This is also how open-source projects like <a href="https://github.com/apex/apex">Apex</a> let developers run Go in AWS Lambda.</p><p>With a 12-line lambda function, I tried running the sshd process on a non-privileged port with a host key and configuration I bundled with my the function. This was a bad idea for several reasons:</p><ul><li>AWS Lambda’s container environment is missing several libraries that the ssh daemon requires.</li><li>AWS Lambda functions do not seem to allow any inbound port access (yes, even if <a href="http://docs.aws.amazon.com/lambda/latest/dg/vpc.html">running in a VPC</a> with a security group that explicitly allows it).</li><li>Exotic ssh configuration files are hard to write and filled with weird options.</li><li>There’s <a href="https://gist.github.com/kixorz/3b172e2fc3ce35421ee9">no easy way to automatically</a> determine the external IP address of a Lambda function.</li></ul><p>It was time for some SSH tunneling and copy-and-paste Golang code from Github.</p><h4>Writing an SSH server that creates a tunnel in Go</h4><p>Go has some nice high-level SSH libraries for creating servers, clients, and tunnels. Unfortunately, my first <a href="https://gist.github.com/jpillora/b480fde82bff51a06238">copy-and-paste attempt</a> had a dependency on an OS feature (<a href="https://en.wikipedia.org/wiki/Pseudoterminal">unix pseudoterminals</a>) that did not exist in the AWS Lambda environment. Digging around a bit more in the Go documentation, I found some libraries designed for interacting with terminals that didn’t have a <a href="https://github.com/kr/pty">dependency on the pty package</a>.</p><p>Cobbling it all together, I had a simple go service that:</p><ul><li>Runs an SSH server capable of executing commands in bash on a non-privileged port.</li><li>Creates a tunnel to a remote host (i.e. my laptop via <a href="https://ngrok.com/">ngrok</a> or an EC2 host running inside my VPC) and requests a port to be opened that forwards to the SSH server running inside the Lambda function.</li></ul><p>I then wrote a Lambda function that:</p><ul><li>Is configured with a 5-minute timeout (the maximum allowed value).</li><li>Executes the Go SSH binary I built for 64-bit Linux (an under-appreciated feature of Go development on macs).</li><li>Used<a href="http://docs.aws.amazon.com/lambda/latest/dg/env_variables.html"> Lambda environment variables</a> to connect to a specific host and port number (i.e. my laptop via a jump proxy).</li></ul><p>With this in place, using the tunnel I can access my go SSH server and run shell commands from another host using a standard SSH client until the Lambda function times out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*LwTTzR9xRfeelnvPBKdVkw.png" /><figcaption>Interacting with the AWS Lambda Environment using faasssh</figcaption></figure><h4>This isn’t a good idea (but it was fun to build)</h4><p>I don’t think creating SSH tunnels and running random servers inside AWS Lambda is a particularly good way to take advantage of serverless, but it was fun to learn more about the execution environment by building it. Couple other possibilities I’m thinking of now that there’s a proof on concept:</p><ul><li>Running other types of servers in Lambda that allow inbound connections through tunneling.</li><li>Integration with a key-management services for SSH authentication (KMS or Vault perhaps?)</li><li>Support for concurrent sessions or integration with a TCP load balancer.</li></ul><p>The code is up on Github (project name: <a href="https://github.com/smithclay/faassh">faassh</a>). Pull requests and questions welcome.</p><p>In the next few weeks, I’ll be at<a href="http://www.devopsdaysaustin.com/"> DevOpsDays Austin</a> and <a href="http://gluecon.com/">Gluecon</a> speaking more about FaaS if you want to chat in person.</p><h4>Links</h4><ul><li><a href="https://speakerdeck.com/smithclay/searching-for-the-server-in-serverless">“Searching for the Server in Serverless”</a> talk (dotScale Paris 2017)</li><li><a href="https://speakerdeck.com/smithclay/serverless-measurement-limits">“Serverless Measurement Limits”</a> talk (DevOpsDays Austin)</li><li><a href="https://blog.newrelic.com/2017/01/11/aws-lambda-cold-start-optimization/">Measuring Cold Starts in AWS Lambda</a> (New Relic Blog Post)</li><li><a href="https://github.com/smithclay/faassh">faash source code</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c940cebf7646" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clog/ssh-ing-into-your-aws-lambda-functions-c940cebf7646">SSH-ing into your AWS Lambda Functions</a> was originally published in <a href="https://medium.com/clog">clog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>