<?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 Tuomo Varis on Medium]]></title>
        <description><![CDATA[Stories by Tuomo Varis on Medium]]></description>
        <link>https://medium.com/@tuomovee?source=rss-a9b19c625092------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Tuomo Varis on Medium</title>
            <link>https://medium.com/@tuomovee?source=rss-a9b19c625092------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:27:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuomovee/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[My key takeaways from ServerlessDays Stockholm]]></title>
            <link>https://medium.com/@tuomovee/my-key-takeaways-from-serverlessdays-stockholm-c852a5ca9e71?source=rss-a9b19c625092------2</link>
            <guid isPermaLink="false">https://medium.com/p/c852a5ca9e71</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverlessdays]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Tuomo Varis]]></dc:creator>
            <pubDate>Sat, 26 Oct 2019 07:46:26 GMT</pubDate>
            <atom:updated>2019-10-26T08:50:28.380Z</atom:updated>
            <content:encoded><![CDATA[<h4>After a day of 10 talks from experts on serverless technologies drawing from real-world experience, here’s what I picked up.</h4><p>Ok, so just to show this blog isn’t dead despite having an unfinished draft of a sequel to my (already ancient) Go &amp; SAM post hanging around for a year I thought I’d share central themes from the ServerlessDays Stockholm conference I just attended. The event was rather small which created a cozy experience but the speakers and organization were excellent. Thanks to the organizers, speakers and sponsors — I’d be happy to attend again!</p><p>I won’t be summarizing all of the talks, but you can check out the <a href="https://stockholm.serverlessdays.io/">event website</a> for the agenda. Hopefully some slides or recordings will be available there soon as well. As a developer-oriented event the agenda was full of exciting technical tidbits but I’ll try to document some higher level themes here.</p><h3>Serverless is a mindset</h3><p>One reoccurring theme in the talks was that “serverless” is not only a technical concept revolving around Functions as a Service and managed highly scalable databases. Instead, serverless was seen as a drastic change to the way applications are designed and going “serverless first” has implications not only on the programming model but all layers of the application, related tooling and how decision making power is distributed and risks are mitigated in the organizations developing the software.</p><p>That sounded an awful lot like marketingspeak so should we append serverless to the long list of buzzwords that supposedly change everything but everyone has their own definitions of (think Agile, DevOps…)? Let’s try to flesh out the serverless mindset a little based on the talks. As <a href="https://stockholm.serverlessdays.io/speakers/richard.boyd/">Richard Boyd</a> mentioned in his introductory talk, the lack of heavy up-front investment and focus on building applications from small building blocks enables the “tactical level” of the organization (that’s us doing the hands-on work) to experiment with technology without a huge buy-in or investment from the higher-ups in advance. Meanwhile the usage of fully managed services gives the tactical guys ability to focus on the mission at hand (business) instead of undifferentiated ops work.</p><p>Most real-world applications need some kind of persistence and in her talk “What to do with your data in a serverless world” <a href="https://stockholm.serverlessdays.io/speakers/angela.timofte/">Angela Timofte</a> from Trustpilot shared some of their adventures regarding serverless database offerings when implementing their “Serverless First” strategy where they started to move from self-managed MongoDB clusters to DynamoDB and Aurora Serverless. Importance of monitoring consumed capacity, sensible scaling and deep knowledge on peculiarities of the chosen product were highlighted. The architectural approach chosen by Trustpilot was pragmatic: their general guideline was to consider serverless first, and rely on container-based solutions if applicable serverless solution was not available or was impractical. Plain VM instances they consider legacy that they’re fading out.</p><p><a href="https://stockholm.serverlessdays.io/speakers/efi.merdler.kravitz/">Efi Merdler-Kraviz</a> demonstrated their development process and toolchain at Lumigo whose product is a monitoring tool. Since their product is serverless they ensure reliable end-to-end testing of feature branches by using developer-specific AWS accounts with full instances of their systems, something that might be prohibitively expensive if large monolithic dependencies or pre-provisioned services like traditional databases were involved. However, the serverless mindset shines in their choice of tooling: they run none of their development-related tooling themselves but rely on GitHub for Git repositories, CircleCI for CI/CD and a SaaS product called Lumigo for monitoring.</p><p>What appears to be the core tenet of serverless is to strive for either outsourcing or eliminating anything that doesn’t generate direct business value — like the Business 101 “focus on core competencies” rule applied to a software stack.</p><h3>Power of asynchronous event-driven architectures</h3><p>While hooking up some functions to an HTTP endpoint is a great pattern for implementing microservices, at the conference we saw a few interesting examples of the event-driven programming model of FaaS applied to rather complex business processes.</p><p>In Angela Timofte’s database talk there was an example on how at Trustpilot they improved an existing user data management service based on periodic table scans by refactoring it to an event-driven model. A nice example on how playing to the platform’s strengths can be both cost-efficient and improve service quality.</p><p><a href="https://stockholm.serverlessdays.io/speakers/katarina.svedman/">Katarina Svedman</a> showed how to address some resilience concerns related to <a href="https://martinfowler.com/bliki/CQRS.html">CQRS</a> pattern implementations using event sourcing from Azure Cosmos DB change feeds and <a href="https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-entities">Durable Entities</a> (a thing I didn’t know even existed before the session). The live demo of replaying the events after application changes was quite impressive!</p><p><a href="https://aws.amazon.com/eventbridge/">Amazon EventBridge</a> is a relatively new event bus service from AWS. <a href="https://stockholm.serverlessdays.io/speakers/james.beswick/">James Beswick</a>’s talk described its features and how its pub/sub model can be used to keep components of an application loosely coupled and prevent them from turning into a monolithic serverless spaghetti. EventBridge integrates well with AWS services and custom code but has also built-in support for various existing SaaS applications. It will be very interesting to get some hands-on experience with it.</p><p>While event-driven architectures are not a new idea, serverless approach provides an economical way for implementing them.</p><h3>Methods for dealing with legacy applications</h3><p>Serverless first strategies are a great option when building greenfield applications. Yet, most applications don’t live in a vacuum and most organizations own services implemented in a traditional manner. Rewrites of existing applications to a new architectural pattern pose a huge risk and especially in case of applications in maintenance mode provide little value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hd8gurhOcFghKoo4XuRtyw.jpeg" /><figcaption>This did raise a few eyebrows. Apologies for using my potato to take the picture.</figcaption></figure><p>Containers are a great way to deploy traditional applications to the cloud without changing the programming model. AWS Fargate already provides an excellent way to run them without worrying about the underlying infrastructure. At ServerlessDays <a href="https://stockholm.serverlessdays.io/speakers/bret.mcgowen/">Bret McGowen</a> demonstrated Cloud Run, GCP’s approach to serverless containers. It brings a few very interesting features to the table for running stateless services: request-scoped pricing and scaling, and configurable concurrency (concurrent requests served by the same container instance). Judging on the live demo, a lift-and-shift of an existing HTTP API to Cloud Run can be done with very little effort.</p><p>What if you want to refactor or enhance an existing application using serverless? <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/strangler">The Strangler Pattern</a> mentioned by<a href="https://stockholm.serverlessdays.io/speakers/simon.aronsson/"> Simon Aronsson</a> provides a safe track of incremental applization modernization. Things like AWS Lambda ALB triggers are a great way to achieve this — building “stairs” for existing workloads towards serverless.</p><h3>The serverless community is awesome!</h3><p>It was really exciting to see experienced developers and the representatives from all the major cloud platforms sharing their take on serverless. All the talks provided valuable lessons — even if I didn’t mention them specifically in this post. The event itself was organized extremely well, the vegetarian lunch was tasty and the people were so nice and friendly that even a not-too-outgoing Finnish guy like me traveling alone felt comfortable and welcome.</p><p>From the workshop programme I chose to attend the <a href="https://cdkworkshop.com/">Cloud Development Kit workshop</a> organized by AWS. The instruction provided by Richard Boyd was first class but walking through the workshop individually by using the materials linked above is definitely possible. While I’m still more inclined to define my infrastructure in a declarative manner by using Terraform, CloudFormation or SAM, the opinionated and object-oriented programming model with strong typing provided by CDK seems to take friction away from many things that are less convenient in other methods like applying the least privilege principle to IAM and configuring the Amazon API Gateway. I’m looking forward to experiment more with CDK — but that’s probably a topic for another post, hopefully not taking a year or two to bake.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c852a5ca9e71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Serverless with SAM]]></title>
            <link>https://medium.com/@tuomovee/go-serverless-with-sam-860c62f63ba4?source=rss-a9b19c625092------2</link>
            <guid isPermaLink="false">https://medium.com/p/860c62f63ba4</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws-sam]]></category>
            <dc:creator><![CDATA[Tuomo Varis]]></dc:creator>
            <pubDate>Sun, 28 Oct 2018 18:45:08 GMT</pubDate>
            <atom:updated>2018-10-28T18:45:08.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*ywzD2Xz2fOqfhZjjYVOeBg.png" /><figcaption>Picture of SAM stolen from <a href="https://github.com/awslabs/serverless-application-model">here,</a> Go Gopher by Renee French</figcaption></figure><p>It’s been almost a year since support for the Go programming language in AWS Lambda was announced at re:Invent 2017. Meanwhile the Serverless hype train has gained full steam, FaaS offerings of all major cloud providers have reached a respectable level of maturity and an increasing amount of teams are building applications based on the model while figuring out how to best manage software consisting of a set of managed cloud resources and individually deployable functions. This post is a quick look at one of the approaches: The AWS Serverless Application Model. Since I’m yet to take Go Lambda functions for a proper spin, the small example app is written in Go and available in GitHub (<a href="https://github.com/tuomovee/feelings">https://github.com/tuomovee/feelings</a>).</p><h4>Why Go?</h4><p>At $DAYJOB most of our Lambda functions are in Python — it offers a decent developer experience, good start-up times and is familiar to the whole development team. However when working with AWS APIs I yearn for static typing on almost daily basis. The requests and responses in the AWS SDK are non-trivial and on more than one occasion that has lead to bugs due to wrong assumptions on their structure that have made it all the way to the unit tests of the application. Discovering these things in integration tests or when the code is deployed to dev environment is not fun. Go’s static typing should alleviate at least some of those issues without introducing too much clutter in the code thanks to its lightweight struct literal syntax. In addition to that it’s a delightfully boring/simple language with excellent performance, nice deployment story and a sublime standard library. You may not enjoy it if you absolutely must have generics, exceptions, functional patterns or any programming language features invented after the 1970’s but in the scope of small programs like Lambda functions these are hardly an obstacle.</p><h4>Why SAM?</h4><p>On FaaS platforms the functions don’t live in a vacuum: at the very least they need some integration to the outside world to trigger their execution. Most likely they also depend on some other cloud resources such as persistence layers or messaging systems and permissions to access them. Managing all this manually using management consoles is a bad practice and quickly becomes unfeasible but doing it the Right Way™ requires a considerable amount of code in Infrastructure as Code tools like CloudFormation or Terraform. Fortunately alternative approaches such as the Serverless framework exist. They reduce the amount of code required to deploy serverless applications and dependent resources by abstracting away common details, generating permissions and even configuring full resources such as API gateways automatically. While Serverless is a third party framework, SAM is an open source effort by AWS Labs to provide this functionality as a CloudFormation translator. AWS Labs has also implemented a nice command-line tool that generetes project skeletons, helps with build and deployment tasks and running Lambda functions locally. It also has some surprising shortages in the feature department, some of which we’ll be addressing and working around in the inevitable sequel to this post.</p><h4>The example app</h4><p>The example application is a “Feelings poll”. In this post we’ll be building a back-end API that receives PUTs of respondent’s mood covering the full spectrum of human experience from “very bad” to “very good” discretized into integers on a scale of 0 to 3 and allows the user to GET poll results for a specific date. Why implement something using Google Forms in 5 minutes when you can potentially get hours of fun, a couple of blog posts and a few important lessons out of it?</p><p>The application is structured as follows:</p><pre>.<br>├── Gopkg.lock<br>├── Gopkg.toml<br>├── Makefile<br>├── template.yaml <br>├── cmd<br>│   ├── get<br>│   │   └── get.go<br>│   └── put<br>│       └── put.go<br>└── pkg<br>    └── db<br>        └── db.go</pre><p>The package “db” contains a shared library that provides a couple of types representing our model and funcs to store and fetch them from DynamoDB. This is wrapped by two HTTP verb-specific Go executables that will be deployed to AWS Lambda to handle events from Amazon API Gateway. The project root directory contains Gopkg files used for dependency management by dep (I’m still stuck at Go 1.10 due to GoSublime stable version limitations and never got into vgo), the SAM template and a makefile used to perform common build, packaging and deployment tasks. The latter two are based on ones generated by SAM, so let’s hit the tutorial mode.</p><h3>Getting started with SAM</h3><p>The SAM command-line tool is written in Python so having Python 2.7 installed is a prerequisite. Also Docker and aws-cli are required. The easiest way to install SAM cli is using pip:</p><pre>$ pip install aws-sam-cli</pre><p>SAM has support for plenty of Lambda runtimes and defaults to node.js if not told to do otherwise. Since we’re using Go, run the following command under $GOPATH/src/&lt;optional-github-stuffs&gt;:</p><pre>$ sam init --runtime go1.x --name feelings</pre><p>What you get from this is a basic makefile and a nice small example application that demonstrates the basic structure of a Go lambda handler and a tutorial in the readme. Both the handler example and the readme are worth a read. However, when getting ready to build the application by running “make deps” to install the dependencies we encounter our first gotcha:</p><pre>$ make deps<br>go get -u ./...<br># cd /Users/toumo/go/src/github.com/tuomovee/feelings; git pull — ff-only<br>There is no tracking information for the current branch.<br>Please specify which branch you want to merge with.</pre><p>It looks like the generated makefile assumes that we are working within a git repo already synced with a public upstream origin. Here you have two options depending on what you’re doing and what’s your preference on Go dependency management:</p><ol><li>Keep using go get for dependency management. Either modify the makefile to get the third party dependencies explicitly or set up a remote (for example a public GitHub repo), configure it as an upstream origin and push the code there already in this infant stage.</li><li>Use some other tool like dep, vgo or go mod for dependency management and modify the makefile accordingly. As mentioned earlier I decided to go with dep so I ran “dep init” and made the following modification to Makefile:</li></ol><pre>deps:<br>    dep ensure</pre><p>Regardless of your chosen approach, running “make deps” will now update your dependencies whenever they change and give your collaborators an easy way to install them. Next, let’s build the initial sample app and then run it locally:</p><pre>$ make build<br>$ sam local start-api<br>$ curl localhost:3000/hello<br>Hello, &lt;redacted&gt;</pre><p>In order to deploy to AWS, we need to first create an S3 bucket to act as a temporary storage for our artifacts. After that we can use SAM cli to package the application, generate a transformed version of our template containing references to the packaged artifacts and deploy the application. SAM uses CloudFormation functionality behind the scenes so we could just as well replace every sam command below with “aws cloudformation”:</p><pre>$ aws s3 mb s3://feelings-lambdas<br>$ sam package --template-file template.yaml --s3-bucket feelings-lambdas --output-template-file packaged.yaml<br>$ sam deploy --template-file packaged.yaml --stack-name feelings --capabilities CAPABILITY_IAM</pre><p>It’s also useful to add above commands to Makefile to save a few keystrokes while iterating on our API.</p><p>Now looking for OutputValue for key “HelloWorldAPI” in “aws cloudformation describe-stacks” output should give us the invocation URL of our API. If a GET to the url gives us the expected response (which should be the same as when running locally) we have verified our configuration and tooling are ready for action.</p><h3>Implementing Feelings</h3><p>When structuring SAM applications it’s useful to think of them like applications implemented using some light-weight REST framework/library (net/http, Sinatra, Flask, Express and friends) with the exception that you define the routes (and the middleware-related concerns you can) in the SAM template, AWS API Gateway is your server and your Lambda handlers work as handlers for the routes. Since your whole application is a single deployable unit it’s not necessary nor productive to take a strict approach to dependency management where each Lambda function is its own completely isolated nanoservice with no shared dependenices. Instead you can develop your Go SAM application like any typical application: implement your logic in a set of library packages and the user-facing part in a main package. Since we are using API Gateway Proxy Requests it would be possible to write a single main package to handle all our requests but implementing a separate Lambda function for each method yields a cleaner result with no need to have any routing logic in the handler.</p><h4>The db package</h4><p>The “db” package is the heart and soul of the Feelings poll application. It contains functions for storing and fetching poll results from DynamoDB and the related data structures. Our Lambda handlers are merely thin wrappers around this package. The most interesting part is probably the usage of the statically typed DynamoDB API. While it has the smell of autogeneration and someone might find the fluent interface of the Java client more pleasant to use, I find it at least preferable over JSON/dict-based minefields of the JS and Python versions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2752af57ca3f6b8d37b34f74da3a8933/href">https://medium.com/media/2752af57ca3f6b8d37b34f74da3a8933/href</a></iframe><h4>Lambda handlers and errors</h4><p>As briefly mentioned in the intro, Go lambda functions are executables. In Feelings’ case they handle marshaling and unmarshaling of JSON responses and requests and reporting possible errors to API Gateway.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df0fd81ac2da27a6e9c9a6fda5dce6c2/href">https://medium.com/media/df0fd81ac2da27a6e9c9a6fda5dce6c2/href</a></iframe><p>Go Lambda handler functions can have two return values: the actual response that gets mapped into an HTTP response by API Gateway and an error type variable whose non-nil value beheaves similarily as throwing an exception from the Lambda handler in other languages: the client gets a 5xx status response, the response returned from the handler is discarded and Lambda invocation is considered failed. In cases of errors for which we can blame the client, for example invalid requests, it’s better to return a nil error value and communicate the error situation with a 4xx status code and save invocation failures for cases where you’d like to get an alarm to wake you up in the middle of the night.</p><p>The PUT handler is structurally similar to the GET one and the source is <a href="https://github.com/tuomovee/feelings/blob/master/cmd/put/put.go">here</a>.</p><h4>The SAM template</h4><p>In the first version of the template we rely on the implicit ServerlessRestAPI generated by SAM —the template has only our AWS::Serverless::Function resources and the DynamoDB table. Lambda function permissions are based on SAM Policy Templates and give each handler the required permissions to access the AWS::Serverless::SimpleTable resource.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60a38365e9751abe613a0899c9d31fe8/href">https://medium.com/media/60a38365e9751abe613a0899c9d31fe8/href</a></iframe><p>One make build package deploy later:</p><pre>$ curl -X PUT -d &#39;{&quot;feeling&quot;: 2}&#39; https://ylfr7tt7ae.execute-api.eu-west-1.amazonaws.com/Prod</pre><pre>$ curl https://ylfr7tt7ae.execute-api.eu-west-1.amazonaws.com/Prod/2018-10-27<br>{&quot;date&quot;:&quot;2018-10-27&quot;,&quot;very_bad&quot;:0,&quot;bad&quot;:0,&quot;good&quot;:1,&quot;very_good&quot;:0}</pre><p>Sweet!</p><h3>Conclusion</h3><p>Now we have deployed a small serverless application backend with SAM. There’s a few important pieces missing however — if I’d just press publish on this blog and get to sleep I could find out in the morning that some evil internets person found this article and kindly used the URL in above example to spam a bazillion requests to the API costing me several dollars. So we obviously need some way to secure our APIs. Also if we investigate the generated API on the AWS console we see that we don’t have CORS enabled so integrating our API to some fancy SPA front-end would still require some configuration in SAM side. We’ll get back to that in the next episode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Lh_McWr1aWxG4WViIJEsg.png" /><figcaption>We still have some way to go in the UX department</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=860c62f63ba4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>