<?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 John Titus on Medium]]></title>
        <description><![CDATA[Stories by John Titus on Medium]]></description>
        <link>https://medium.com/@john.titus?source=rss-e69e3ad4fa01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K-3_VwxT-nYPpJoCTFqt5Q.png</url>
            <title>Stories by John Titus on Medium</title>
            <link>https://medium.com/@john.titus?source=rss-e69e3ad4fa01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:20:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@john.titus/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[Unum deployed to Ropsten Testnet]]></title>
            <link>https://medium.com/unum/unum-deployed-to-ropsten-testnet-297f767e86a?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/297f767e86a</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Sun, 26 Nov 2017 22:13:41 GMT</pubDate>
            <atom:updated>2017-11-26T22:18:40.763Z</atom:updated>
            <content:encoded><![CDATA[<p>Unum can now be bought and sold on the Ethereum Ropsten testnet. If you’re using <a href="https://metamask.io/">MetaMask</a>, you can switch to the Ropsten network by clicking on the network name in the top right of the MetaMask interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*sRpBjI_JV0tR85YtJnuJng.png" /></figure><p>If you need some fake Ether, you can get some at the <a href="https://faucet.metamask.io/">MetaMask faucet</a>.</p><p>Once you’re switched over, you can use the <a href="https://unum.one/">Unum.one</a> website to buy and sell Unum and take it out for a test drive. If you run into any issues, let us know at <a href="/service/mailto:support@unum.one">support@unum.one</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=297f767e86a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/unum/unum-deployed-to-ropsten-testnet-297f767e86a">Unum deployed to Ropsten Testnet</a> was originally published in <a href="https://medium.com/unum">Unum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Many, Unum]]></title>
            <link>https://medium.com/unum/from-many-unum-8c8493a8db9d?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c8493a8db9d</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Sun, 26 Nov 2017 21:46:31 GMT</pubDate>
            <atom:updated>2017-11-26T21:46:31.924Z</atom:updated>
            <content:encoded><![CDATA[<p>Everything in cryptocurrency is a scam until proven otherwise.</p><p>Raise your hand if you lost money in the Mt. Gox debacle. Or the <a href="https://en.wikipedia.org/wiki/Bitfinex_hack">Bitfinex hack</a>. Or if you invested in <a href="https://www.cnbc.com/2017/11/23/confido-ceo-who-allegedly-pulled-375k-scam-lied-about-employment.html">Confido</a>. Or if you had funds on <a href="https://www.cryptocoinsnews.com/btc-e-users-funds-stuck-in-limbo-as-companies-blame-each-other/">BTC-e</a>. Or any of the other <a href="https://www.cryptocoinsnews.com/bitcoin-scams/">countless cryptocurrency scams</a>. Hell, if you haven’t lost money in one cryptocurrency scam or hack you probably haven’t been into cryptocurrency very long.</p><p>The power of cryptocurrency comes from its decentralized nature, and anytime someone asks you to “trust” them, whether it’s a new cryptocurrency exchange, or a new ICO, or even a new currency, you should be very, very wary. Trust and cryptocurrency do not mix.</p><p>I created Unum because I believe a price-stable cryptocurrency is essential to increased adoption of cryptocurrency by businesses, and because I don’t believe any of the existing price-stable cryptocurrencies are a good solution. They either require a tremendous amount of trust (<em>“Sure, we back all of our currency with fiat, you can trust us!”</em>) or are just bizarrely complicated (<em>“Our price stable cryptocurrency is backed by dividends from our 2 other cryptocurrencies which allow users to short one currency…”</em>).</p><p>Unum is implemented as a smart contract on the Ethereum blockchain. You can purchase Unum by sending Ether or other ERC20 tokens, like OMG or EOS, to the smart contract. In return you’ll be credited with an amount of Unum equivalent to the US dollar value of whatever you sent in. Send in $20 worth of QTUM, get about 20 Unum. Thus, Unum’s value is backed by the value of many other cryptocurrencies. From many, Unum.</p><p>The currency you send in is held by the Unum Smart Contract as a reserve. You can trade Unum for any currency held in the reserve, again on a US dollar equivalent basis. Send in 20 Unum, and you can get about $20 of Ether, or OMG, or any other supported token.</p><p>I said “about” because there is a small conversion fee when buying or selling Unum — 0.05% is withheld as a conversion fee, which is used to pay to update the price oracle that maintains the US dollar rates of each of the supported tokens. If you buy or sell $100 with the Unum smart contract, $0.05 would be kept as a fee.</p><p>Because Unum is a smart contract, you can audit it’s reserves instantly on the block chain. And because it’s a smart contract, you can review the source code to see what I, the owner, can and cannot do. Most importantly, I cannot withdraw from the reserve. There’s literally no way to do it. I also cannot make money out of thin air by issuing Unum. The only way I can get Unum is to send in Ether or another token — just like anyone else.</p><p>You can learn more about Unum at <a href="https://unum.one/">https://unum.one</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c8493a8db9d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/unum/from-many-unum-8c8493a8db9d">From Many, Unum</a> was originally published in <a href="https://medium.com/unum">Unum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welcome to Picture Guardian]]></title>
            <link>https://medium.com/picture-guardian/welcome-to-picture-guardian-807dd8fe95d9?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/807dd8fe95d9</guid>
            <category><![CDATA[photography]]></category>
            <category><![CDATA[entrepreneurship]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Tue, 29 Mar 2016 13:10:47 GMT</pubDate>
            <atom:updated>2016-03-29T13:10:47.195Z</atom:updated>
            <content:encoded><![CDATA[<p>Picture Guardian is now live, meaning you can sign up and start finding out where your photos are being used online. Both the Personal and Professional plans include a 30-day free trial, no credit card required.</p><h4>Why we made Picture Guardian</h4><p>In 2011, we created <a href="https://www.watermarquee.com/">Water Marquee</a>, a site that lets photographers watermark their photos. Over the years since then, we’ve heard from many of our users that their <strong>photos were being stolen even with a watermark</strong>. Unfortunately, it’s pretty easy to either remove a watermark or to just crop it off of the photo.</p><p>And of course, there are plenty of people who don’t want to add a watermark to their pictures in the first place. They feel it detracts from the overal aesthetic, and would rather take their chances than ruin their art.</p><p>When people do appropriate photos, they usually do it without considering the photo’s creator. Some of our Water Marquee users had success just contacting the people who were using their photos without permission and getting them to take it down. But it’s impossible to be constantly vigilant if you have more than a few photos in your portfolio.</p><p>Which brings us to Picture Guardian. Picture Guardian will search the internet to find where your photos are showing up. When it finds your photos online, it will email you to let you know, so that you can investigate further.</p><p>Our hope is that, with Picture Guardian, you can rest easy knowing that your photos are protected.</p><h4>How to get started</h4><p>First, you’ll need to <a href="https://www.pictureguardian.com/signup">sign up</a> for one of our plans. Both options come with a 30-day free trial and don’t require a credit card to get started, so you can find out if it’s worth it for you.</p><p>After that, you can check out our <a href="https://pictureguardian.com/getting-started">Getting Started</a> guide. It will walk you through uploading your photos and what search results look like.</p><h4>What do you think?</h4><p>Picture Guardian is brand new, and we’d very much like to hear from you. You can reach us at <a href="/service/mailto:support@pictureguardian.com">support@pictureguardian.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=807dd8fe95d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/picture-guardian/welcome-to-picture-guardian-807dd8fe95d9">Welcome to Picture Guardian</a> was originally published in <a href="https://medium.com/picture-guardian">Picture Guardian</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The One Way XML Beats JSON]]></title>
            <link>https://medium.com/@john.titus/the-one-way-xml-beats-json-8613b9484463?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/8613b9484463</guid>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Thu, 18 Feb 2016 18:33:49 GMT</pubDate>
            <atom:updated>2016-02-18T18:35:27.246Z</atom:updated>
            <content:encoded><![CDATA[<p>Let me start by stating I’m not a fan of XML. I find it to be too verbose, and as a developer who uses Javascript all day, I usually hate working with XML. The various libraries I’ve used to convert it into a usable format seem to fall short and do weird things like wrap arrays in variables called ‘$’.</p><p>By definition, Javascript and JSON just go together, and working with JSON makes my life simpler.</p><p>That said, I did recently come across one feature of XML that JSON just can’t compare to: storing data about data, also called metadata.</p><p>Let’s say we have an array in JSON:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e1986b5de038dae26159201f868b01f/href">https://medium.com/media/8e1986b5de038dae26159201f868b01f/href</a></iframe><p>A similar array in XML:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b0defa0b18b6951655318f037fba53b/href">https://medium.com/media/7b0defa0b18b6951655318f037fba53b/href</a></iframe><p>So far so good. The problem arises when you want to add information about each result. Say you want to add access control information. The xml could look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34bdfac6ad0ce489c6ce142ffc1cd9e4/href">https://medium.com/media/34bdfac6ad0ce489c6ce142ffc1cd9e4/href</a></iframe><p>There’s just no good way to do that in JSON. You could add a new attribute to each JSON result object, but that’s polluting the data with information ABOUT the data. If your data gets more complicated than a simple array, and you need metadata at different levels, it can get confusing very quickly.</p><p>There’s a few proposed ways to add metadata to JSON, but there’s no standard, which means there’s no tooling built around it. If you know otherwise, let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8613b9484463" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get the Public IP Address from Inside an AWS Lambda]]></title>
            <link>https://medium.com/@john.titus/how-to-get-the-public-ip-address-from-inside-an-aws-lambda-fcce8898a569?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcce8898a569</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Fri, 02 Oct 2015 00:49:26 GMT</pubDate>
            <atom:updated>2015-10-02T00:49:26.734Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c6642ff7f0b986f8da8b0e225d83869/href">https://medium.com/media/1c6642ff7f0b986f8da8b0e225d83869/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcce8898a569" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Thaumaturgy]]></title>
            <link>https://medium.com/@john.titus/introducing-thaumaturgy-8657e1c866d2?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/8657e1c866d2</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Wed, 30 Sep 2015 17:05:44 GMT</pubDate>
            <atom:updated>2015-09-30T17:05:44.158Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS Lambda lets you use Node modules, but you have to include them in your Zip file when you upload it. It won’t grab modules via NPM or anything like that.</p><p>The problem is that AWS Lambda is running on an Amazon Linux install, so some Node modules won’t work if you’ve built them on your own machine running Windows, OS X, or just a different version of Linux.</p><p>To fix this problem, you’d have to spin up an EC2 instance running Amazon Linux, install Node/NPM, copy your code over to the new instance, ‘npm install’, then copy the contents back to your box, THEN create your Lambda zip. It was a pain.</p><p>So I made <a href="https://github.com/node-hocus-pocus/thaumaturgy">Thaumaturgy</a>. It’s a command line tool that creates an AWS Lambda whose sole purpose is to build Node modules for you.</p><p>Let’s say you need to build mysql2. You can build it with Thaumaturgy like this:</p><blockquote>thaumaturgy build mysql2:0.15.8</blockquote><p>That will spin up the Thaumaturgy Lambda and tell it to grab <em>mysql2</em> from NPM, build it, and store the results in S3 as a Zip file. If you’d prefer, you can use the ‘ — download’ flag to tell Thaumaturgy to download the results for you automatically.</p><p>You can have Thaumaturgy build a list of packages, or even just read a <em>package.json</em> file and build all the dependencies in it.</p><p>Happy Lambda-ing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8657e1c866d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run a Node.js Express app in Amazon’s AWS API Gateway]]></title>
            <link>https://medium.com/@john.titus/how-to-run-a-node-js-express-app-in-amazon-s-aws-api-gateway-84a54d21dca7?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/84a54d21dca7</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Mon, 31 Aug 2015 16:02:23 GMT</pubDate>
            <atom:updated>2015-08-31T16:02:23.146Z</atom:updated>
            <content:encoded><![CDATA[<p>Amazon’s <a href="https://aws.amazon.com/api-gateway/">API Gateway</a> lets you run a web application without having to create and scale your own web server cluster. Instead, you define endpoints in the API Gateway that point to an <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> function.</p><p>It’s a great pattern from a cost point of view. API Gateway costs $3.50 per million API calls received, plus the cost of data transfer out. AWS Lambda costs based on the number of requests per month, plus a cost for the duration of execution and the amount of memory consumed. If your app isn’t used very much, you cost is going to be very low. If it does get a lot of usage, you’ll be able to scale up automatically. No installing servers, no maintenance, and linear pricing.</p><p>Most Node.js developers use <a href="http://expressjs.com/">Express</a>, or something that derives from it like <a href="http://locomotivejs.org/">Locomotive</a>. Transitioning to the AWS API Gateway might seem daunting, because you have to start over from scratch writing Lambdas. There goes all that lovely Express middle-ware, rendering, etc.</p><p>To help with the transition, I’ve created <a href="https://github.com/johntitus/legerdemain">Legerdemain</a>. It lets you run your entire Express app as a Lambda with very minimal work. Legerdemain is brand new and I’m sure there are a lot of kinks to work out, but I’ve been able to run a full Express app on AWS API Gateway with it.</p><p>Setting up API Gateway to work is still a pain. You have to create your routes all over again, by hand. You also have to do some work to configure the mappings per method. I hope to release an automated way to do this in the future.</p><p>If you encounter any problems with Legerdemain, please open an <a href="https://github.com/johntitus/legerdemain/issues">issue</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84a54d21dca7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving a simple API to Amazon’s API Gateway]]></title>
            <link>https://medium.com/@john.titus/moving-a-simple-api-to-amazon-s-api-gateway-680d025e0921?source=rss-e69e3ad4fa01------2</link>
            <guid isPermaLink="false">https://medium.com/p/680d025e0921</guid>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[John Titus]]></dc:creator>
            <pubDate>Mon, 13 Jul 2015 17:32:32 GMT</pubDate>
            <atom:updated>2015-07-13T17:32:32.523Z</atom:updated>
            <content:encoded><![CDATA[<p>Last week, Amazon announced their new <a href="https://aws.amazon.com/blogs/aws/amazon-api-gateway-build-and-run-scalable-application-backends/">API Gateway</a>. Among other interesting use cases, the one that attracted me was the ability to hook it up to a <a href="http://aws.amazon.com/lambda/">Lambda</a> function. This can allow you to have an API without having to worry about scaling your infrastructure at all. I’ve been wanting to play with Lambda for awhile, but didn’t really have a good excuse to use it - until now.</p><p>I created <a href="http://aretheplanetsaligned.com/">AreThePlanetsAligned.com</a> awhile ago as a simple way to see how long it would take to build a quick website/API and get it online. It was hosted on <a href="https://www.heroku.com/">Heroku</a>, which at the time had a very generous introductory plan that let you run small apps essentially free, forever. They’ve since modified their pricing a bit — free apps now must sleep for at least 6 hours a day. If you want even a small app up 24/7, you have to pay $7/month. Still quite generous, but that can add up for devs who, like myself, have several “hobby” apps lying around.</p><p>Most of my apps are constructed as an API first, with a web UI connecting to it. That approach makes it a bit easier to debug when something goes wrong. And now it makes it very straightforward to move my little apps to make use of Amazon’s API Gateway, and how the UI on S3. Here’s how I did moved AreThePlanetsAligned from Heroku to AWS.</p><h3>Creating a new API</h3><p>If you don’t have one already, you’ll need to sign up for an <a href="http://aws.amazon.com/console/">AWS account</a> before you can create an API. Once you have that, log into the AWS console and click on the new <a href="https://console.aws.amazon.com/apigateway/home">API Gateway</a> under Application Services. Click the <strong>Create API</strong> button, and fill out the API name and description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70b87Rh9vze57FAfU_y7_w.png" /><figcaption>Your API will automatically be given HTTPS endpoints.</figcaption></figure><p>The API Gateway will automatically create a Root resource for you. You can attach methods to this endpoint if you want, but I created a new child Resource under the root called “alignments”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5k7W-hWaA-RWh53UPm_7w.png" /></figure><p>The new child resource shows up under the “/” (the root resource of your API). It doesn’t have any methods yet (like GET or POST); we’ll add those in a bit.</p><h3>Creating an Access Policy in IAM</h3><p>Before you can attach your API to a Lambda function you’ll need to setup a policy that will allow Lambda to execute code. This policy is defined in the <strong>Identity and Access Management</strong> (IAM) part of AWS. After you open IAM, click the <strong>Policies </strong>link in the navigation area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHtDYFa3qvD1aQ4noWbYFQ.png" /><figcaption>IAM has many pre-made policies, but we’re going to create a new one.</figcaption></figure><p>Click the Create Policy button to add a new policy. The <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html">AWS API Gateway Getting Started guide</a> has an <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started.html#getting-started-new-lambda">example policy</a> you can use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqvBXDAcAwnSgeoPuzAHFw.png" /><figcaption>This policy lets Lambda access Cloudwatch Logs. Your policy may need to grant access to S3, Dynamo, or other AWS tools, depending on your needs.</figcaption></figure><p>After you’ve created the policy, you’ll need to create a Role to access that Policy. Back in IAM, click on the <strong>Roles </strong>link and then on the <strong>Create New Role</strong> button. You’ll be asked to provide a Role name, and then to attach a Policy to that Role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p7gjNElYRuAyZZNWo8iHXQ.png" /><figcaption>Be sure to attach the policy we just created to this new Role.</figcaption></figure><p>AWS will then let you review the role before you click the final Create Role button.</p><h3>Creating your Lambda Function</h3><p>At this point, we have our API partially implemented and a Role ready to go. Now it’s time to create the brains of your API — the Lambda function that will get called whenever your API endpoint gets requested.</p><p>Back at the AWS console, click on the Lambda link under the Compute heading. Skip the Select Blueprint options, and you’ll land on the New Function page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRbKgZsvpat970uE92CxNg.png" /><figcaption>The code for my API is derived from the <a href="https://github.com/johntitus/planetary/blob/master/lib/index.js">Planetary</a> Node.js module.</figcaption></figure><p>You’ll need to give the function a name, description, runtime (defaults to Node.js), and the code itself. You can edit the code inline if it’s straightforward and has no dependencies. If it’s more complex, you’ll need to upload a Zip file containing everything that it needs access to.</p><p>If you’re writing in Node.js, you’ll need to expose a “handler” method that Lambda knows to call. The default is<strong> index.handler</strong>, which in your code becomes “exports.handler”. You’ll also need to give this Lambda function a Role — the same one we created above. You can also modify the amount of memory available to the function and a timeout setting if you’d like. I stuck with the defaults of 128 MB and 3 seconds.</p><p>After you save the function you’ll be given a chance to Review it, and then to test it. This allows you to pass in some variables and see what the Lambda returns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hzbpVNWi5AJqLSRUL_4sVA.png" /><figcaption>Make sure you test your Lambda before proceeding.</figcaption></figure><h3>Adding an API Method</h3><p>Now that the brains of our API are ready, we can hook our API up to the Lambda function.</p><p>Back in the API Gateway, click the Create Method button, select the HTTP method you need (I used GET), and click the tiny check mark when you’ve selected the one you want. You’ll be taken to the method Setup screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPQYkcX33SG_Db7YycShdQ.png" /></figure><p>You’ll be asked for an Integration Type, in this case Lambda Function, and the name of the Function. When you click Save you’ll get a modal window asking you to “Add Permission to Lambda Function”. This gives the API Gateway permission to invoke your Lambda code, so click OK.</p><p>You’ll be taken to the Method Execution screen, which shows you exactly how a request will work from a Client, to your Lambda function, and back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZOux7C7fOWiILeG8xQ-AA.png" /><figcaption>The Method Execution screen shows you how requests will be handled.</figcaption></figure><p>If everything looks in order, it’s time to deploy your API. You can deploy to different stages, named however you wish. You’ll likely want to deploy first to a Testing stage, and then in the future deploy to a Production stage if everything works all right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwHTN_4Ezl30A9HCRWYidQ.png" /></figure><p>After you deploy, you’ll be given an end point from which you can access your API. If your method is GET, you can likely call your resource from the browser (note you’ll need to modify the URL Amazon gives you by tacking on the resource name). Otherwise, you can curl it to be sure everything is working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BweBzRLt2AE6Uua9voBQg.png" /><figcaption>You can also view your Lambda function’s Monitoring tab to verify the API endpoint is hitting the function.</figcaption></figure><p>At this point, your API is working, but you may want to take some additional steps, likes supporting CORS so your API can be called from a browser and moving your static website to S3.</p><h3>CORS Support for your API</h3><p>If you want to let people access your API from JavaScript in a browser, you’ll need to support Cross-origin Resource Sharing (CORS). Amazon’s API Gateway let’s you do this by modifying the Method Response and Integration Response, so that your API returns the Headers the browser is looking for.</p><p>From your Resource’s Method Execution screen, click on the Method Response box. Expand the “200” status, and click the Add Header button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQ27soV5PrkuJKDZnVA73Q.png" /></figure><p>You’ll need to add the following headers:</p><ul><li>Access-Control-Allow-Headers</li><li>Access-Control-Allow-Methods</li><li>Access-Control-Allow-Origin</li></ul><p>When you’re done, return to the Method Execution screen, and click on the Integration Response box. Here’s where you’ll actually set the value of those headers, under the 200 response, like so:</p><ul><li>Access-Control-Allow-Headers = ‘Content-Type,X-Amz-Date,Authorization’</li><li>Access-Control-Allow-Methods = ‘GET’</li><li>Access-Control-Allow-Origin = ‘*’</li></ul><p><strong>You do need to put a single quote around the value of each header.</strong></p><p>After you save the Integration Response, you should be able to use AJAX to call your API. Note that you’ll need support CORS on the client JavaScript as well.</p><h3>Hosting your Website with S3</h3><p>Now that the brains of the API are inside the API Gateway, there’s no more need to have a web server just to host a static website. Instead, we’ll dump everything into S3, and let Amazon handle that for us, too!</p><p>Create a new Bucket in S3, and modify the Bucket Policy to make the contents GetObject action accessible to anyone. Amazon has an <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html">example policy</a> you can use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*mU-eHp1JNMTWWXMZkAJeLg.png" /><figcaption>Change the resource to your actual bucket name.</figcaption></figure><p>You’ll also need to expand the Static Website Hosting option and click the Enable website hosting option, and point it at your root document, such as index.html.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOuC2d3X--2iWxp5YteqQg.png" /></figure><p>Then you can <a href="http://docs.aws.amazon.com/cli/latest/reference/s3/sync.html">use the AWS CLI to sync your static contents to S3</a>.</p><p>That’s it — a website and an API without any web servers. You can take it even further if your API is more complicated, by making use of AWS’s many other features like Dyanmo or CloudSearch. It’s amazon how you can create a very powerful, complicated service without having any servers. Now if Amazon would just write the code for you…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=680d025e0921" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>