<?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 Preston Tamkin on Medium]]></title>
        <description><![CDATA[Stories by Preston Tamkin on Medium]]></description>
        <link>https://medium.com/@Prestomation?source=rss-4b91c240ae3f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JWdUrKnxL1O1Ughf.</url>
            <title>Stories by Preston Tamkin on Medium</title>
            <link>https://medium.com/@Prestomation?source=rss-4b91c240ae3f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:42:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Prestomation/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[Using the DynamoDB Document Client with DynamoDB Streams from AWS Lambda]]></title>
            <link>https://medium.com/a-cloud-guru/using-the-dynamodb-document-client-with-dynamodb-streams-from-aws-lambda-6957b6c81112?source=rss-4b91c240ae3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6957b6c81112</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Preston Tamkin]]></dc:creator>
            <pubDate>Wed, 10 May 2017 07:19:33 GMT</pubDate>
            <atom:updated>2017-05-14T23:39:13.885Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use DynamoDB Document Client with AWS Lambda DynamoDB Streams</h3><h4>Your DynamoDB Streaming code running in Lambda can have the same niceties of JS objects provided by the DocumentClient</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SeI7NsBhizLIYZYPHcc50w.png" /></figure><h4>DynamoDB has a cumbersome ‘type system’</h4><p>When using DynamoDB, the API can take a little getting used to. One of the more annoying parts of the API is how attribute data types are specified. Each Item Attribute is itself a map with only one key, where the key signifies the datatype, like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bd70a15af6802d001c2708ebe1dc814/href">https://medium.com/media/9bd70a15af6802d001c2708ebe1dc814/href</a></iframe><p>This means you can’t just access an attribute by saying item.attribute, you must say item.attribute.TYPE. Well, what if you don’t know the type? You could make the argument ‘This attribute is always a string, so let’s just assume it’s a string’, but you never know when someone in the future may change it’s type, either purposefully or in error.</p><h4>AWS SDKs to the rescue!</h4><p>Fortunately, most (all?) of the AWS SDKs attempt to ease some of this burden. Statically-typed languages like Java have added a layer on top of the raw API to do sensible things using the type system. Javascript has the ‘DocumentClient’ which automatically unmarshalls the DynamoDB data model into a more native-feeling javascript object.</p><p>Compare the two gists below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20496b017502cbbfbce4f20c1fda68f9/href">https://medium.com/media/20496b017502cbbfbce4f20c1fda68f9/href</a></iframe><p>The above is way easier to manage than the ‘raw API’ as you see below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3765398d0156263e679491c8efcd27ee/href">https://medium.com/media/3765398d0156263e679491c8efcd27ee/href</a></iframe><p>Now this is all well and good, there is never a time when you <strong><em>wouldn’t </em></strong>use the DocumentClient …<strong>unless you’re using DynamoDB Streams</strong></p><h4>The trouble with using DynamoDB Streams</h4><p>DynamoDB Streams is a feature where you can stream changes off your DynamoDB table. This allows you to use the table itself as a source for events in an asynchronous manner, with other benefits that you get from having a partition-ordered stream of changes from your DynamoDB table.</p><p>The problem is, when you use AWS Lambda to poll your streams, you lose the benefits of the DocumentClient! You are no longer calling DynamoDB at all from your code. Your Lambda is invoked with the body from the stream. You never are ‘given the chance’ to insert the DocumentClient in the right place to do this JS object translation for you.</p><p><strong>The good news is … we can tap into this translator directly!</strong></p><p>I did some digging and learned how to pull the nice object translation layer out of the DocumentClient and invoke it directly. See the gist below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d44ac80381d9c08a83dcdf91e148f0e1/href">https://medium.com/media/d44ac80381d9c08a83dcdf91e148f0e1/href</a></iframe><p>That’s all there is to it! Your DynamoDB Streaming code running in Lambda now has the niceties of JS objects as provided by the DocumentClient.</p><p>Some notes:</p><ul><li>This is in no way using public APIs from the SDK. These could change or go away at anytime. I protect from this issue by always including my own AWS SDK in my build — so Lambda SDK upgrades won’t break me — and thus my local integration tests will catch a SDK break.</li><li>You may be able to use a single translateOutput call using the getRecords shape directly. I didn’t try very hard to make this work.</li></ul><p>That’s it for this post. I hope this helps you cut down on a lot of the boilerplate in your DynamoDB Streaming listeners.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6957b6c81112" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/using-the-dynamodb-document-client-with-dynamodb-streams-from-aws-lambda-6957b6c81112">Using the DynamoDB Document Client with DynamoDB Streams from AWS Lambda</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking the AWS JS SDK: Signing AWS IoT Websockets in the browser using the AWS JS SDK]]></title>
            <link>https://medium.com/@Prestomation/hacking-the-aws-js-sdk-signing-aws-iot-websockets-in-the-browser-using-the-aws-js-sdk-153b23203db?source=rss-4b91c240ae3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/153b23203db</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-iot]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Preston Tamkin]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 21:14:58 GMT</pubDate>
            <atom:updated>2017-04-18T21:39:02.675Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS IoT is a pretty awesome service that launched at re:Invent 2015(<a href="https://www.youtube.com/watch?v=fm4Aa3Whwos">I co-hosted a breakout session that year</a>). AWS IoT is: a low-latency, scalable pub/sub service, a rules engine to fit many popular subscription usecases with no code, a ‘thing database’ where devices can store an offline state, certificate security(for shipped hardware IoT devices) and more.</p><p>For the general purpose webapp #serverless community, it is AWS’s first infinitely scalable websocket service. If you’re building a serverless app and you need real-time publish/subscribe that you would have previously fired up a socket.io service for, then AWS IoT is the service for you@</p><p>One problem, the toolset support is just not there yet! You may say ‘but Preston, it’s just a websocket!’ Yes it is, but security throws a wrench into this whole thing. To my knowledge, this is the only public facing Websocket API that Amazon has(AVS, the Alexa Voice Service, skipped websockets and went directly to HTTP2). None of the AWS SDKs have any websocket support built-in and, to my knowledge, the AWS sigv4 security algorithm has no websocket-specific specification.</p><p>The only help AWS gives you towards authenticating using IoT websockets is <a href="http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html">this document</a> with these <a href="https://gist.github.com/prestomation/24b959e51250a8723b9a5a4f70dcae08">~40 lines of javascript</a>. One odd thing about this code is…it still uses the AWS javascript SDK! It’s odd because it uses sha256 and hmac algorithms from the SDK internals, but doesn’t use any of the sigv4 signers directly(<a href="https://medium.com/@Prestomation/swaggerjs-api-explorer-using-aws-sigv4-authentication-on-amazon-api-gateway-2883f66f35c1">like I do in my SwaggerJS sigv4 adapter</a>)</p><p>While I’ve been using this code successfully in production for sometime it just..rubs me the wrong way to have to have a 2nd implementation of the top-level of the sigv4 algorithm in my code. so I set out to remove this code duplication.</p><p>Here are a few observations I made while examining this code</p><ul><li>The service name is ‘iotdevicegateway’. A service name that appears nowhere in the SDKs</li><li>The endresult is simply a URL with the sigv4 components in the URL(usually they are headers). This is nearly the same result you get when calling ‘req.presign()’ with the javascript SDK.</li></ul><p>So I took a stab at monkey patching the SDK to presign an IoT websocket connection URL. <strong>The primary problem I had was that AWS IoT does NOT allow you to sign the security token header!</strong></p><p><a href="http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html">The sigv4 documentation mentions that services act inconsistently:</a></p><blockquote>For some services, you must include the X-Amz-Security-Token query parameter in the canonical (signed) query string. For other services, you add the X-Amz-Security-Token parameter at the end, after you calculate the signature. For details, see the API reference documentation for that service.</blockquote><p><a href="http://docs.aws.amazon.com/iot/latest/developerguide/protocols.html">And the AWS IoT documentation DOES sorta mention this</a>:</p><blockquote>If you have session credentials (from an STS server, AssumeRole, or Amazon Cognito), append the session token to the end of the URL string after signing:</blockquote><p>Anyway, I ended up with this hacky thing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c7cb201f279b62c27ae1dcf826ff0fd/href">https://medium.com/media/6c7cb201f279b62c27ae1dcf826ff0fd/href</a></iframe><p>Yep, <em>deleting</em> the session token from our credential object(so it doesn’t get signed) and then restoring it afterwards. We’re also tapping into the req state machine to adjust the path(because we’re using a fake request).</p><p>Guess what?</p><h3>IT WORKS!</h3><p>Was it worth it? I dunno. But I’m going to use it.</p><p>My original intention was to provide a nicer, shorter piece of code than what AWS provides to make using IoT in the browser a little simpler. While I achieved ‘shorter’, I’m not sure I actually achieved ‘nicer’.</p><p>Oh well.</p><p><strong><em>Amazon, please allow AWS IoT to accept signed session tokens!</em></strong></p><p><strong><em>Disclaimer: Don’t blame me if this stops working in the future due to internal SDK changes. I warned you!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=153b23203db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless SlackOps: Real-time linking to Logs when your Lambda function crashes]]></title>
            <link>https://medium.com/@Prestomation/serverless-slackops-real-time-linking-to-logs-when-your-lambda-function-crashes-edbd8e0353e1?source=rss-4b91c240ae3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/edbd8e0353e1</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudwatch]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Preston Tamkin]]></dc:creator>
            <pubDate>Mon, 03 Apr 2017 04:24:19 GMT</pubDate>
            <atom:updated>2017-04-03T04:33:06.469Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@Prestomation/serverless-slackops-real-time-error-notifications-with-deep-linking-to-cloudwatch-logs-6aa225c19304">Last week I wrote</a> about deep-linking to the Cloudwatch Logs console from your Lambda functions. The problem with this is..it only works if you can catch the error! What about when an unhandled error crashes the Lambda runtime?</p><p>My first thought was to use a global Node exception handler like process.on(“uncaughtException”). There are <a href="https://forums.aws.amazon.com/thread.jspa?threadID=229830">multiple</a> <a href="https://forums.aws.amazon.com/thread.jspa?threadID=241288">reports </a>online of this simply not working. I also tried it myself, and the handler is not executed.</p><p>So what are our other options?</p><p>I decided upon the following:</p><ul><li>A Cloudwatch Logs subscription filter on every lambda log group with a filter for the string Lambda emits when a function crashes. This string is “Process exited before completing request”</li><li>A Lambda as the destination for the subscription above. Due to the filter, this function is only invoked when another function crashes. The input from Cloudwatch Logs contains the source log group/stream and time which gives us enough info to form a deep-link into the Cloudwatch Logs console!</li></ul><p>I’ve combined all this together into a Cloudformation template to demonstrate the minimally required resources:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ecb42d856682554becddfb4c95c05f1/href">https://medium.com/media/1ecb42d856682554becddfb4c95c05f1/href</a></iframe><p>This gist creates:</p><ul><li>A Lambda that always crashes</li><li>Pre-creates the above function’s Log Group so that we can attach a subscription to it</li><li>The Logging Lambda with inline code that forms the deep link</li><li>The Log Subscription</li><li>A minimal Lambda Execution Role</li><li>Permission on the Logging Lambda so Cloudwatch Logs may Invoke it</li></ul><p>If you modify this code to send to your Slack instance and invoke the crashing lambda, you’ll see something like this in Slack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*69jAZJdZQhsA75UPCot3rA.png" /><figcaption>Example Log Message in Slack, with a link to CloudWatch Logs</figcaption></figure><p>If you click this link, you’ll be deeplinked to exactly where the error happened. Of course, you may send this link wherever is appropriate</p><p>Some other thoughts:</p><ul><li>This may only be applicable to NodeJS. This is the only runtime I use so I don’t actually know. In the synchronous languages you can probably just use a try/catch at the top-level.</li><li>You can print the string ‘Process exited before completing request’ in your applications Lambdas when you want to be alerted of something in the error log. You don’t necessarily have to crash the Lambda</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edbd8e0353e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless SlackOps: Real-time error notifications with deep-linking to Cloudwatch Logs.]]></title>
            <link>https://medium.com/a-cloud-guru/serverless-slackops-real-time-error-notifications-with-deep-linking-to-cloudwatch-logs-6aa225c19304?source=rss-4b91c240ae3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6aa225c19304</guid>
            <category><![CDATA[cloudwatch]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[slack]]></category>
            <dc:creator><![CDATA[Preston Tamkin]]></dc:creator>
            <pubDate>Mon, 27 Mar 2017 06:46:21 GMT</pubDate>
            <atom:updated>2018-04-12T06:49:05.801Z</atom:updated>
            <content:encoded><![CDATA[<p>When building a first serverless application on AWS Lambda, many engineers quickly realize that they have to rethink their logging and metrics collection strategies. Due to the runtime model of AWS Lambda, you can no longer run your usual logging daemon of choice. Fortunately, AWS Lambda ships some excellent basic metrics and logging out of the box via Cloudwatch which go a long way to solving usual logging and metrics use cases.</p><p>At my current startup, I have embraced the idea of ‘SlackOps’: using Slack as a first tier support, monitoring, and even alarming tool. For example, we have platform integration such that high-value customer activities, such as signups, are reported in a slack channel. We also conduct customer support chat on our website using a 3rd party service that surfaces the chat to us through Slack. ALL team communication then ends up in Slack which is very convenient.</p><p>Combining the above two ideas, I extended the platform to report errors to slack as they occur. This is all well in good, but anyone who has used Lambda+Cloudwatch Logs knows that log diving is not always an easy experience. This prompted me to explore whether the platform could deep link to Cloudwatch Logs.</p><p>As it turns out, it was possible. The Lambda context object contains the name of the log group and log stream. Taking these, along with the current time, and forming a Cloudwatch Logs Console URL allows easy, real-time deep linking to the Cloudwatch Console. The demonstrative NodeJS code snippet below demonstrates the basic idea, using a fictitious ‘postNotification’ method to post a notification with the deeplink.</p><pre>var AWS = require(&#39;aws-sdk&#39;);</pre><pre>module.exports.handler = function(event, context, callback)<br>{<br>  var link= https://console.aws.amazon.com/cloudwatch/home?region=REGION#logEventViewer:group=LOG_GROUP;stream=LOG_STREAM;start=START&quot;;</pre><pre>  link = link.replace(“REGION”, AWS.config.region); <br>  link = link.replace(“LOG_GROUP”, context.logGroupName);<br>  link = link.replace(“LOG_STREAM”, context.logStreamName);<br>  link = link.replace(“START”, new Date().toISOString());</pre><pre>  <br>  postNotification(&quot;An Error Occurred:&quot; + link);<br>  callback(&quot;error&quot;); <br>}</pre><p>In my actual implementation, I wrap the toplevel callback with functionality that determines, for every call, whether or not to post to Slack and to generate the notification text itself. I also use Slack formatting so a nice link is used instead of the raw URL.</p><p>I hope this post helps you better leverage Cloudwatch Logs in your serverless application monitoring. Of course, this is usable in any sort of notification, not just Slack.</p><p>Do you have any tips for monitoring your serverless application? Are there facets of serverless application development that you find difficult or frustrating that you’d like me to write about? Let me know in a response below!</p><p>Disclaimer: The Cloudwatch Logs URL is reverse-engineered from my own use of the console. These deeplinks could theoretically go away or change at anytime</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6aa225c19304" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/serverless-slackops-real-time-error-notifications-with-deep-linking-to-cloudwatch-logs-6aa225c19304">Serverless SlackOps: Real-time error notifications with deep-linking to Cloudwatch Logs.</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwaggerJS/API Explorer using AWS Sigv4 authentication on Amazon API Gateway.]]></title>
            <link>https://medium.com/a-cloud-guru/swaggerjs-api-explorer-using-aws-sigv4-authentication-on-amazon-api-gateway-2883f66f35c1?source=rss-4b91c240ae3f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2883f66f35c1</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws-api-gateway]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <dc:creator><![CDATA[Preston Tamkin]]></dc:creator>
            <pubDate>Sun, 19 Mar 2017 04:22:45 GMT</pubDate>
            <atom:updated>2017-03-19T04:33:32.354Z</atom:updated>
            <content:encoded><![CDATA[<p>The AWS Lambda+API Gateway serverless stack has become immensely popular in the past couple of years. It is very easy to get started building APIs at a very low cost that will scale with you and your business(or remain free for your toy project). That said, I have found that many developers building on the AWS serverless stack have a difficult time understanding their authentication/authorization options, let alone picking the right option for them and understanding all the tooling involved.</p><p>While not the most flexible option available, the easiest authentication method to start with for API Gateway is ‘AWS_IAM’. With this option, API access is gated by IAM policy and can take advantage of AWS Sigv4 features like pre-signing. This is the best option if these APIs are accessed from your own compute nodes that already have IAM roles available to them(e.g. your code on EC2 or Lambda) or from end user-facing applications using Cognito Identity Pools.</p><p>A ‘problem’ with this approach is that AWS Sigv4 is <a href="http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html">pretty complicated</a>. API Gateway will <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk.html">generate SDKs for you in a number of popular languages</a> but…they kind of suck and now you have a bunch more dependencies to manage during build and run-time. So..<strong><em>what if you could just ‘steal’ the signing logic from the AWS SDKs you probably already use in your application</em></strong>?</p><p>Another very interesting aspect about API Gateway is it’s Swagger support. Even if you don’t build your API in Swagger, you can still export a Swagger definition from API Gateway.</p><p>Putting these ideas together, I built a simple <a href="https://github.com/prestomation/swagger-ui/blob/master/dist/client_authorization-sigv4.js">Client Authorization implementation</a> for SwaggerJS that is a simple adapter..pulling the signing code from the AWS JS SDK and signing ‘sigv4’ requests for SwaggerJS.</p><p>I went one step further and, with a few changes to the demo page for SwaggerUI(A handy API Explorer), <a href="http://prestomation-blog-demos.s3-website.us-east-2.amazonaws.com/swagger/index.html#/default">built a simple live API Gateway API Explorer</a>(<a href="https://github.com/prestomation/swagger-ui/blob/master/dist/index.html">source</a>). Just enter your API Gateway region, API Id, Stage Name, and access/secret key and start exploring your API as currently deployed.</p><p>(Don’t worry, I promise I’m not stealing your credentials. This is entirely in the browser).</p><p>This example pulls together the AWS JS SDK, SwaggerJS, Swagger UI, and less than 100 lines of new code to provide a powerful demonstration of leveraging existing technologies to secure your severless APIs while not reinventing any wheels. You can most likely extend this technique to other platforms that AWS supports but API Gateway does not yet generate an SDK for.</p><p>Are you using Swagger clients for your serverless APIs? Do you want to learn more about serverless and serverless security? Let me know in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2883f66f35c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/a-cloud-guru/swaggerjs-api-explorer-using-aws-sigv4-authentication-on-amazon-api-gateway-2883f66f35c1">SwaggerJS/API Explorer using AWS Sigv4 authentication on Amazon API Gateway.</a> was originally published in <a href="https://medium.com/a-cloud-guru">A Cloud Guru</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>