<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.3">Jekyll</generator><link href="https://dannyvarner.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://dannyvarner.com/" rel="alternate" type="text/html" /><updated>2019-10-20T22:21:16+00:00</updated><id>https://dannyvarner.com/</id><title type="html">Danny Varner</title><subtitle>I'm Danny Varner. I write about code and agile software teams from Portland, OR.
</subtitle><entry><title type="html">How The Big Cloud Providers Fail at IDaaS: Scorecard</title><link href="https://dannyvarner.com/2019/10/20/idaas-scorecard.html" rel="alternate" type="text/html" title="How The Big Cloud Providers Fail at IDaaS: Scorecard" /><published>2019-10-20T22:12:14+00:00</published><updated>2019-10-20T22:12:14+00:00</updated><id>https://dannyvarner.com/2019/10/20/idaas-scorecard</id><content type="html" xml:base="https://dannyvarner.com/2019/10/20/idaas-scorecard.html">&lt;p&gt;&lt;em&gt;See Part 1 of this post: &lt;a href=&quot;/2019/09/14/big-cloud-fails-at-identity-intro.html&quot;&gt;How The Big Cloud Providers Fail at IDaaS: Heuristics&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the previous post I outlined my heuristics for evaluating IDaaS offerings
in the big cloud providers. The post put heavy emphasis on
spec-compliance to OpenID Connect (OIDC) in the context of a
&lt;a href=&quot;https://jamstack.org/&quot;&gt;JAMstack&lt;/a&gt;. JAMStack provides a highly
scalable, well-vetted, and low-cost method for building out a web app and OIDC provides well-vetted and secure authentication and authorization. The teaser in that post was that all
the cloud providers fail to provide a fully managed OIDC based identity
service. Let’s dig in.&lt;/p&gt;

&lt;h2 id=&quot;identity-as-a-service-in-big-cloud&quot;&gt;Identity as a Service in Big Cloud&lt;/h2&gt;

&lt;p&gt;The IDaaS offerings by the big three are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/cognito/&quot;&gt;AWS Cognito&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://cloud.google.com/identity-platform/&quot;&gt;Google Cloud Identity Platform&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://azure.microsoft.com/en-us/services/active-directory-b2c/&quot;&gt;Azure Active Directory B2C&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I’ll also briefly touch on &lt;a href=&quot;https://auth0.com&quot;&gt;Auth0&lt;/a&gt; as they are a clear leader in this space and actually do provide spec compliance.&lt;/p&gt;

&lt;p&gt;The 8 focus points of my evaluation are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Choice of Social Federation&lt;/li&gt;
  &lt;li&gt;Choice of Custom Login&lt;/li&gt;
  &lt;li&gt;Account Linking&lt;/li&gt;
  &lt;li&gt;Fully Managed Service&lt;/li&gt;
  &lt;li&gt;Brand Control&lt;/li&gt;
  &lt;li&gt;OIDC Discovery Endpoint&lt;/li&gt;
  &lt;li&gt;Authorization Code Flow w/ PKCE&lt;/li&gt;
  &lt;li&gt;Silent Refresh&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check back to &lt;a href=&quot;/2019/09/14/big-cloud-fails-at-identity-intro.html&quot;&gt;How The Big Cloud Providers Fail at IDaaS: Heuristics&lt;/a&gt; on why these are important.&lt;/p&gt;

&lt;h2 id=&quot;before-we-begin-google-identity-platform-is-not-an-oidc-compliant-idaas-provider&quot;&gt;Before we begin: Google Identity Platform is NOT an OIDC compliant IDaaS provider&lt;/h2&gt;

&lt;p&gt;AWS, Azure, and Auth0 all follow the same architectural pattern regarding OIDC for their IDaaS offering. They all attempt to provide an OIDC compliant endpoint which has the ability to the federate with varying social logins. This makes it easy for developers to integrate with these services using OIDC compliant libraries. You can think of it as OIDC on both sides: Client uses OIDC to connect with the IDaaS offering and then the IDaaS offering uses OIDC to connect with the potential social logins. This shows the flexibility of the OIDC spec:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/oidc-signin-azure-cognito.png&quot; alt=&quot;Cognito/Azure/Auth0 Architecture&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Google on the other hand, has opted to expose the signup/signin flows through their proprietary Firebase SDK. They only have implemented OIDC compliance on &lt;em&gt;one side of the equation&lt;/em&gt;. Google Identity can use any OIDC compatible identity provider as a form of authentication but Google Identity itself is not OIDC compatible. There is no OIDC discovery endpoint. The only option is to use their proprietary SDKs or APIs.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/oidc-signin-google.png&quot; alt=&quot;Google Architecture&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This needlessly create lock-in as it breaks away from spec compliance forcing all flows to go through their custom SDK/APIs rather than standard OIDC flows. What I’m looking for in a IDaaS provider is true OIDC compliance, so this really takes Google’s offering out of the runnings.&lt;/p&gt;

&lt;p&gt;In addition, Google’s offerings are very difficult to parse as they have &lt;strong&gt;three&lt;/strong&gt; separate services targeted toward consumer facing web applications. Google has an identity crisis with its identity offerings:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;em&gt;&lt;a href=&quot;https://developers.google.com/identity/sign-in/web&quot;&gt;Google Sign-in&lt;/a&gt;&lt;/em&gt;: This enables integrating Google Social Sign in (and &lt;em&gt;only&lt;/em&gt; Google Social Sign in) into an application.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;&lt;a href=&quot;https://firebase.google.com/docs/auth&quot;&gt;Firebase Authentication&lt;/a&gt;&lt;/em&gt;: This enables integrating many types of identity providers into an application.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;&lt;a href=&quot;https://cloud.google.com/identity-platform/&quot;&gt;Google Identity Platform&lt;/a&gt;&lt;/em&gt;: This appears to be just a wrapper around Firebase Authentication but branded and packaged as Google Cloud service.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this analysis I’m just looking at Google Identity Platform/Firebase as I’m not interested in restricting users to only being able to login with a Google account. My guess is that firebase will eventually get fully rolled into the Google Cloud brand.&lt;/p&gt;

&lt;p&gt;Onto the scoring!&lt;/p&gt;

&lt;h3 id=&quot;choice-of-social-federation-and-custom-login&quot;&gt;Choice of Social Federation and Custom Login&lt;/h3&gt;

&lt;p&gt;All the providers provide mechanisms for Social Logins and direct username/password sign in flows. Nothing interesting to see here!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Everyone Wins!&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;account-linking&quot;&gt;Account Linking&lt;/h3&gt;

&lt;p&gt;All the cloud offerings provide a way to consolidate identities through account linking when users choose to login via multiple paths (e.g. Username/Password one session, Google Sign-in next session). This does require some custom UI and API calls in the application to sign in and link the additional identities. Examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://firebase.google.com/docs/auth/web/account-linking&quot;&gt;Google Account Linking&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminLinkProviderForUser.html&quot;&gt;Cognito Account Linking&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/Azure-Samples/active-directory-b2c-advanced-policies/tree/master/account-linking&quot;&gt;Azure Account Linking&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Everyone wins!&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;fully-managed&quot;&gt;Fully Managed&lt;/h3&gt;

&lt;p&gt;Cognito, Azure, and Auth0 all provide hosted UIs for the signin/signup page due to their OIDC compliance. This makes it as easy as possible for the developer to quickly get identity integrated with minimal code.&lt;/p&gt;

&lt;p&gt;Since Google does not provide an OIDC compliant endpoint, the developer is left to implementing the UI for sign in and sign up on their own with help from the Firebase SDK.&lt;/p&gt;

&lt;p&gt;It should be noted that AWS Cognito appears to be moving in a similar direction as Google by promoting their Amplify SDK as a custom, locked-in, mechanism for interacting with the Cognito Authorization Server.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Google Cloud fails in providing a fully managed offering by forcing users to implement the signup/signin flows using their Firebase SDK&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;brand-control&quot;&gt;Brand Control&lt;/h3&gt;

&lt;p&gt;Azure and AWS both provide options for UI customization in their hosted logins to get the account chooser to match brand with custom CSS and custom logos.&lt;/p&gt;

&lt;p&gt;However, when it comes to providing a custom domain, Azure is the only provider that &lt;a href=&quot;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-faqs#can-i-use-my-own-urls-on-my-sign-up-and-sign-in-pages-that-are-served-by-azure-ad-b2c-for-instance-can-i-change-the-url-from-loginmicrosoftonlinecom-to-logincontosocom&quot;&gt;currently does not offer this capability&lt;/a&gt;. The identity page is hosted at https://&amp;lt;your-tenant-name&amp;gt;.b2clogin.com. That login looks nothing less than suspect. This is unfortunate given all the security advocates out there training users to pay close attention to domain names in protection of phishing attempts. This just makes it confusing for end users.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/azure-b2c.png&quot; alt=&quot;Azure's Sketchy Login&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The positive of Google’s approach with the Firebase SDK is you do get more brand control as that they have explicitly opted to not host any UI themselves. All signin flows are built by the developer using Firebase SDK.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Azure fails with no option for custom domains&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;oidc-discovery-endpoint&quot;&gt;OIDC Discovery Endpoint&lt;/h3&gt;

&lt;p&gt;The OIDC Discovery endpoint for Cognito can be viewed &lt;a href=&quot;https://cognito-idp.us-west-2.amazonaws.com/us-west-2_1VtBS1gkB/.well-known/openid-configuration&quot;&gt;here&lt;/a&gt;. As part of OIDC compliance, the discovery endpoint should advertise &lt;code class=&quot;highlighter-rouge&quot;&gt;response_types_supported&lt;/code&gt; which informs the client &lt;a href=&quot;https://openid.net/specs/openid-connect-core-1_0.html#Authentication&quot;&gt;which types of OIDC flows can be requested&lt;/a&gt;. The OIDC spec calls out the required values of &lt;code class=&quot;highlighter-rouge&quot;&gt;code&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;id_token&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;token id_token&lt;/code&gt;. So far so good, Cognito exposes the discovery endpoint and lists those 3 required OAuth 2.0 response types as required by the spec. Open the link up and see for yourself.&lt;/p&gt;

&lt;p&gt;Unfortunately, this is &lt;em&gt;completely misleading&lt;/em&gt; as Cognito only supports response types of &lt;code class=&quot;highlighter-rouge&quot;&gt;token&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;code&lt;/code&gt; as can be seen in their &lt;a href=&quot;https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html&quot;&gt;docs&lt;/a&gt;. Requesting any of the other response types results in an HTTP 400 error. This results in generic client OIDC libs to break when initiating the Implicit Flow with Cognito as they expect the Discovery Endpoint to be accurate.&lt;/p&gt;

&lt;p&gt;Azure also has issues with its Discovery Endpoint. Another purpose of the Discovery Endpoint is to advertise the Authorization Endpoint for initiating the auth flow. Azure has a problem in that the Discovery Endpoint publishes one Authorization Endpoint but the docs instruct the clients to use a &lt;em&gt;different&lt;/em&gt; authorization endpoint:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Authorization Endpoint Source&lt;/th&gt;
      &lt;th&gt;Authorization Endpoint&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://towerscouter.b2clogin.com/towerscouter.onmicrosoft.com/b2c_1_towerscouter/.well-known/openid-configuration&quot;&gt;Discovery endpoint&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;https://towerscouter.b2clogin.com/towerscouter.onmicrosoft.com/b2c_1_towerscouter/oauth2/authorize&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-spa&quot;&gt;Docs&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;https://towerscouter.b2clogin.com/towerscouter.onmicrosoft.com/b2c_1_towerscouter/oauth2/V2.0/authorize&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;This may be fine if both the authorization endpoints worked as advertised, but only the V2.0 endpoint was able to complete the desired flows making the Discovery Endpoint rather useless.&lt;/p&gt;

&lt;p&gt;Google doesn’t expose an OIDC Discovery Endpoint at all for their Identity Service. You are stuck using their SDKs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Azure and AWS both have failures in the accuracy of their Discovery Endpoint. Google Cloud Identity doesn’t even offer a Discovery Endpoint.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;authorization-code-with-pkce&quot;&gt;Authorization Code with PKCE&lt;/h3&gt;

&lt;p&gt;As mentioned in my previous post, the IETF is recommending clients stop using the Implicit Flow in favor of the Authorization Code with PKCE for the web. For the Authorization Code Flow with PKCE to work
the Authorization Server must support CORS on the token endpoint for the
client to successfully make the exchange.&lt;/p&gt;

&lt;p&gt;Unfortunately Azure AD B2C does not
support CORS on their token endpoint breaking any ability to move from the
Implicit Flow to the more secure Authorization Code with PKCE.&lt;/p&gt;

&lt;p&gt;This is yet another heuristic that cannot be applied to Google’s architecture due to forcing the use of the Firebase SDK.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Result: Azure and Google fail to provide the more secure Authorization Code with PKCE.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;silent-refresh&quot;&gt;Silent Refresh&lt;/h3&gt;

&lt;p&gt;Another good security measure when implementing OIDC flows on the web is to leverage Silent Refresh. This allows the client to refresh the short-lived access token via an invisible IFrame if the user still has a valid session with the Identity Provider.&lt;/p&gt;

&lt;p&gt;AWS Cognito is unable to do a Silent Refresh. Attempting to to pass &lt;code class=&quot;highlighter-rouge&quot;&gt;prompt=none&lt;/code&gt; when calling the &lt;code class=&quot;highlighter-rouge&quot;&gt;/authorize&lt;/code&gt; endpoint will result in a 400 error. An alternative is to store the refresh token in local storage or session storage to perform a silent refresh, but this is considered a poor security practice as the refresh token is long-lived and browser storage is notoriously insecure.&lt;/p&gt;

&lt;p&gt;Although Google Identity presumably supports a silent refresh via the Firebase SDK it is not using the standard &lt;code class=&quot;highlighter-rouge&quot;&gt;prompt=none&lt;/code&gt; OIDC flow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scorecard: Azure strong. Cognito weak. Google is still hiding behind its SDK&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;a-note-on-auth0&quot;&gt;A note on Auth0&lt;/h2&gt;

&lt;p&gt;Auth0 is a SaaS offering that focuses on the identity space exclusively. They are clearly the leaders in their spec compliance, documentation and ease of use beating anything that the big cloud providers offer. However, it does come at a price. They have a free tier with base functionality but certain features require a paid plan like brand control and account linking.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Criteria&lt;/th&gt;
      &lt;th&gt;AWS Cognito&lt;/th&gt;
      &lt;th&gt;Azure AD B2C&lt;/th&gt;
      &lt;th&gt;Google Identity&lt;/th&gt;
      &lt;th&gt;Auth0&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Social Federation&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Password Login&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Account Linking&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅💲&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fully Managed&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Brand Control&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;✅💲&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OIDC Discovery Endpoint&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;🚫&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Authorization Code Flow + PKCE&lt;/td&gt;
      &lt;td&gt;✅ ️&lt;/td&gt;
      &lt;td&gt;🚫&lt;/td&gt;
      &lt;td&gt;🚫&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Silent Refresh&lt;/td&gt;
      &lt;td&gt;🚫 ️&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
      &lt;td&gt;⚠️&lt;/td&gt;
      &lt;td&gt;✅&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;I value using industry standards for security, user privacy, and transparency. Using standards means I also don’t have to re-learn a new provider specific API/protocol. It also provides flexibility in reusing standard spec compliant SDKs/libraries in my language of choice for speed of development.&lt;/p&gt;

&lt;p&gt;With both the OAuth2/OIDC specs being out in the wild for 5+ years I’m disappointed to see these standards not more widely embraced by the IDaaS offerings by the major cloud providers. It’s promising to see Auth0 fill the void that the cloud providers have left by coming out with a very robust, service that has all the benefits of spec compliance.&lt;/p&gt;

&lt;p&gt;I do wonder though, with the difficulty the cloud providers have in getting spec compliance with OIDC, is part of the blame on the standard itself for not being easier to adopt? Is OIDC too heavy for the average web application? Is it perhaps too customized for the enterprise and not the cash strapped startup or enthusiast hobby project which needs to move quickly? Or is it all on the cloud providers?&lt;/p&gt;

&lt;p&gt;In short, how did Identity get so horribly complicated?&lt;/p&gt;</content><author><name></name></author><category term="identity" /><category term="oidc" /><category term="oauth2" /><category term="idaas" /><summary type="html">See Part 1 of this post: How The Big Cloud Providers Fail at IDaaS: Heuristics</summary></entry><entry><title type="html">How The Big Cloud Providers Fail at IDaaS: Heuristics</title><link href="https://dannyvarner.com/2019/09/14/big-cloud-fails-at-identity-intro.html" rel="alternate" type="text/html" title="How The Big Cloud Providers Fail at IDaaS: Heuristics" /><published>2019-09-14T13:30:14+00:00</published><updated>2019-09-14T13:30:14+00:00</updated><id>https://dannyvarner.com/2019/09/14/big-cloud-fails-at-identity-intro</id><content type="html" xml:base="https://dannyvarner.com/2019/09/14/big-cloud-fails-at-identity-intro.html">&lt;p&gt;I started looking for an Identity as a Service (IDaaS) offering recently for my hobby project &lt;a href=&quot;https://towerscouter.com&quot;&gt;Tower Scouter&lt;/a&gt;. When I’m thinking of IDaaS I’m thinking of a service that handles all of the authentication, authorization and user management for my application so that I can spend less time on these well-solved problems and more time on what makes my application unique.&lt;/p&gt;

&lt;p&gt;Identity is something that &lt;em&gt;literally&lt;/em&gt; every SaaS startup is going to need to provide a solution for. Surely IDaaS would be a commodity offering in all the big cloud providers given the generally accepted standards of OAuth2 and OpedID Connect (OIDC). Right?&lt;/p&gt;

&lt;p&gt;Nope. It turns out that all the cloud providers have significant gaps in providing a spec-compliant IDaaS offering.&lt;/p&gt;

&lt;p&gt;Don’t get me wrong, there are IDaaS offerings by the big three: Google Identity Platform, AWS Cognito, and Azure Active Directory B2C. They all have simple getting started guides, tons of usage and SDKs to quickly integrate the service into an application. But if you look under the hood it turns out they all have major disconnects with how the protocol should work as defined in the official OAuth2/OIDC specs.&lt;/p&gt;

&lt;h2 id=&quot;overview-on-oauth2-and-oidc&quot;&gt;Overview on OAuth2 and OIDC&lt;/h2&gt;

&lt;p&gt;OAuth2 specification was published in 2012 and has been a cornerstone for providing a standard mechanism to securely handle the communication paths between the multiple parties involved during an authorization handshake. The parties are described in detail within the &lt;a href=&quot;https://tools.ietf.org/html/rfc6749&quot;&gt;official spec&lt;/a&gt;, which is quite readable. To summarize:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OAuth2 Parties&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The Resource Owner (e.g. an end-user)&lt;/li&gt;
  &lt;li&gt;Client (Requests access to a protected resource on behalf of the Resource Owner, e.g. a Single Page App, a mobile app)&lt;/li&gt;
  &lt;li&gt;Authorization Server (Issues access tokens to Client after authenticating and authorizing the Resource Owner, e.g. Login with Google/Facebook, AWS Cognito, Auth0)&lt;/li&gt;
  &lt;li&gt;Resource Server (e.g. a Protected API)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Although this provided a standard way of authorization (can they get in?), the OAuth2 spec intentionally left out any specifics on how to perform the authentication (who is this user?). OpenID Connect (OIDC) came into the picture two years later as a layer on top of OAuth2 as the standard &lt;em&gt;authentication&lt;/em&gt; layer. This provided a standard way for describing a user via claims (e.g. name, email, etc) through a JSON Web Token (JWT). The JWT is a specific implementation of the generic OAuth2 ‘access token’.&lt;/p&gt;

&lt;p&gt;Just to make things confusing, the OIDC spec also renamed a couple of the OAuth2 parties:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Resource Owner is now just referred to as just ‘End-User`&lt;/li&gt;
  &lt;li&gt;Authorization Server is now referred to as an ‘OIDC Provider’ (OP)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A typical flow may look something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/idaas-flow-lg.png&quot; alt=&quot;IDaaS Flow username/password&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In this case, the user chose to authenticate directly with OP via username and password. It would also be possible for the user (via an account chooser) to select one of the federated identity providers and login directly via that channel.&lt;/p&gt;

&lt;h2 id=&quot;heuristics-for-evaluating-idaas&quot;&gt;Heuristics for Evaluating IDaaS&lt;/h2&gt;

&lt;p&gt;There are some rule of thumb heuristics that I have defined for evaluating each of the IDaaS offerings. Note that these heuristics are based on the context of a lean startup mentality of wanting to rapidly spin up an identity solution to focus in on the real business logic. A large enterprise mentality would appropriately have different heuristics when looking at identity management (e.g. SAML integrations, auditability, compliance, pricing at scale, etc).&lt;/p&gt;

&lt;p&gt;This is what I’m looking for in IDaaS offering:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Choice of Social Federation&lt;/strong&gt;: I’d like to offer my users their choice of logging in with their preferred social login. This reduces barriers for my users to signup by allowing them to use an existing login. It also protects my users in that they can avoid creating another custom username/password for my service.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Choice of Custom Login&lt;/strong&gt;: For the users that prefer not to use a social provider as a login, I still want to provide them the ability to create a custom username and password. In this case, I want the entire signup flow provided to me by the identity service. The signup flow UI, the enforcement of password requirements, the email confirmation, and the forgot password flow are all well-solved flows I’d rather not build myself.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Account Linking&lt;/strong&gt;: One problem with multiple options for social login is that the user is now burdened with remembering which social login they used for that specific site. I’d like to be able to have a single identity across social logins and username/password so that a user can log in in several different ways and I can have a single identity for that user.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Fully Managed Service&lt;/strong&gt;: Fully managed in the sense that I don’t want my application to have to deal with any sign-in/sign up logic. I want to redirect the users to a fully managed authorization endpoint that provides a UI for all the sign-in and signup flow. This provides increased security for my users as I never have to see the user’s password, even if they are creating a custom username/password for my site. I expect all these sign-in/signup flow are easily configurable from a pleasant to use management portal to quickly and easily make changes to the login experience and to manually administer users.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Brand Control&lt;/strong&gt;: Although the custom login flow should ideally work out of the box, I would like the ability to customize the styling to match my brand. Beyond custom logos/colors I’d also like to be able to provide a custom domain so the user isn’t confused by seeing a different domain in the browser URL or the ‘from address’ during email signup flows.&lt;/p&gt;

    &lt;p&gt;⚠️Warning: These next 3 points get pretty nitty-gritty in the OAuth2/OIDC spec specifics, feel free to gloss over!&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OIDC Discovery Endpoint&lt;/strong&gt;: The &lt;a href=&quot;https://openid.net/specs/openid-connect-discovery-1_0.html&quot;&gt;OpenID Connect Discovery Spec&lt;/a&gt; requires providers to expose the needed information for clients to interact with the provider in a standard way. This is done by exposing the endpoint of &lt;code class=&quot;highlighter-rouge&quot;&gt;/.well-known/openid-configuration&lt;/code&gt; that details the authorization endpoint, the public certificate endpoint, and other supported features of the Authorization Server. This is important as having spec-compliant OIDC Discovery Endpoint in my IDaaS offering means I can easily reuse generic client-side libraries implementing the OIDC spec to securely implement the desired flows.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Authorization Code Flow w/ PKCE&lt;/strong&gt;: Recently the Internet Engineering Taskforce (IETF) has &lt;a href=&quot;https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13#section-3.1.2&quot;&gt;published a
draft&lt;/a&gt;
recommending to NOT use Implicit flow for increased security. Their recommendation is to replace the implicit flow with the
&lt;a href=&quot;https://tools.ietf.org/html/rfc7636&quot;&gt;Authorization Code Flow with PKCE&lt;/a&gt; for Single Page Apps. The
migration path from Implicit Flow to Authorization Code Flow w/ PKCE isn’t
too difficult. Namely, the client will not receive an access token directly in
the callback URL but rather an authorization code which can then be exchanged
with the Authorization Server for the desired access token. This helps to limit exposure of the sensitive access token.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Silent Refresh&lt;/strong&gt;: A common practice for keeping a user logged in using the Implicit Flow or Authorization Code Flow w/ PKCE is to perform a Silent Refresh by opening an invisible iframe and attempting to get a new access token with a fresh expiration timestamp. This is &lt;a href=&quot;https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest&quot;&gt;outlined in the spec&lt;/a&gt; by providing the &lt;code class=&quot;highlighter-rouge&quot;&gt;prompt&lt;/code&gt; parameter to the authorization endpoint with the value of &lt;code class=&quot;highlighter-rouge&quot;&gt;none&lt;/code&gt;. This provides a seamless way to keep users logged in without requiring long-lived access tokens.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That’s my criteria. In the next post, I’ll dive into how each of the cloud providers stacks up to these heuristics. What heuristics are important to you in an IDaaS offering? Is spec-compliance worth sweating about if it ‘just works’?&lt;/p&gt;</content><author><name></name></author><category term="identity" /><category term="oidc" /><category term="oauth2" /><category term="idaas" /><summary type="html">I started looking for an Identity as a Service (IDaaS) offering recently for my hobby project Tower Scouter. When I’m thinking of IDaaS I’m thinking of a service that handles all of the authentication, authorization and user management for my application so that I can spend less time on these well-solved problems and more time on what makes my application unique.</summary></entry><entry><title type="html">Serverless Secrets Management</title><link href="https://dannyvarner.com/2018/12/24/serverless-secrets.html" rel="alternate" type="text/html" title="Serverless Secrets Management" /><published>2018-12-24T13:30:14+00:00</published><updated>2018-12-24T13:30:14+00:00</updated><id>https://dannyvarner.com/2018/12/24/serverless-secrets</id><content type="html" xml:base="https://dannyvarner.com/2018/12/24/serverless-secrets.html">&lt;p&gt;Getting started securing secrets in AWS Lambda is confusing at best and downright frightening at worst.  You are faced with understanding and comparing KMS, Parameter Store, Secrets Manager, and Secure Environment Variables.  You need to consider whether you are going to be retrieving secrets at run time, deploy time or a hybrid.  And when you do retrieve the secrets you also are faced with deciding on whether to retrieve them decrypted or encrypted for later manual decryption.&lt;/p&gt;

&lt;p&gt;With so many options, it’s way too easy to get this wrong.  To make matters worse, there are many solutions, plugins, blogs, and resources out there that conflict in their recommendations.  In this post we’ll look at some common sense security goals, the options available to the Lambda developer using the Serverless Framework, and how these options stack up to the security goals.&lt;/p&gt;

&lt;h2 id=&quot;the-secret-management-problem&quot;&gt;The Secret Management Problem&lt;/h2&gt;

&lt;p&gt;When developing an application, whether it is serverless or not, eventually
you are confronted with how to deal with secrets that are needed for your
application to run but you don’t want exposed to anyone else. These are
things like API keys or database credentials. Common solutions to secret management are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Hard code your secret in source control.&lt;/strong&gt; You’re not &lt;em&gt;really&lt;/em&gt; considering this are you?  Albeit, if you store &lt;em&gt;encrypted&lt;/em&gt; secrets in source control this is OK.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Read your secrets from Environment Variables&lt;/strong&gt;. Popular with &lt;a href=&quot;https://12factor.net/&quot;&gt;The Twelve-Factor App&lt;/a&gt;.  Commonly the Environment Variables are populated from the ‘secure variables’ section that most, if not all, Continuous Integration services provide.  This keeps the secrets out of source control and are fairly easy to manage via the CI provider.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Retrieve your secrets from a secret management service at runtime&lt;/strong&gt;.  Very secure but can be complex to setup.  This includes things like AWS Parameter Store, AWS Secrets  Manager, and Hashicorp Vault.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;the-secret-management-goals&quot;&gt;The Secret Management Goals&lt;/h2&gt;
&lt;p&gt;The requirement for secret management will vary based on application to application.  For the purposes of this analysis I’ll be looking at the following functional and non-functional requirements:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Secrets must be encrypted at rest&lt;/li&gt;
  &lt;li&gt;Secrets must be encrypted in transit&lt;/li&gt;
  &lt;li&gt;Ease of Use&lt;/li&gt;
  &lt;li&gt;Pricing&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep in mind, that this is not an exhaustive list!  Certainly, other things like PCI compliance,     principle of least privilege, auditable history, and performance impacts could be applicable for your application.&lt;/p&gt;

&lt;h2 id=&quot;deciphering-aws-secret-management-services&quot;&gt;Deciphering AWS Secret Management Services&lt;/h2&gt;
&lt;p&gt;AWS provides three services for serverless secret management: Lambda itself via Environment Variables, System Manager Parameter Store, and Secrets Manager.  All three of these are built upon the AWS Key Management Service (KMS).  Let’s start by looking at KMS.&lt;/p&gt;

&lt;h3 id=&quot;kms&quot;&gt;KMS&lt;/h3&gt;
&lt;p&gt;A common misconception is that KMS can store your arbitrary secrets.   This is NOT what KMS does.  KMS primarily does two things:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;It provides an extremely secure way to store &lt;em&gt;symmetric encryption keys&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;It provides APIs that allow an authorized IAM user to utilize those encryption keys without ever exposing the actual keys.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that important difference, KMS stores encryption keys, not the secrets themselves.  This is why KMS is the common foundation to other AWS based secret management solutions.&lt;/p&gt;

&lt;p&gt;The encryption keys stored in KMS really are designed to be accessible by &lt;em&gt;nobody&lt;/em&gt;.  The encryption keys live in a FIPS 140-2 Hardware Security Module (HSM).   They have &lt;a href=&quot;https://csrc.nist.gov/projects/cryptographic-module-validation-program/Certificate/3139&quot;&gt;external audits by the NIST Cryptographic Module Verification Program&lt;/a&gt;.  There is Ethan Hunt proof physical security that will zero out all keys if the pick-resistant locks are broken into.  The encrypted secrets all utilize the AES-256 algorithm that would take all of the computing power on earth more time than the age of the universe to brute force crack&lt;sup id=&quot;fnref:1&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ethanhunt.jpg&quot; alt=&quot;Ethan Hunt&quot; /&gt;
The security in KMS is appropriately intense as it really is a foundational component in the AWS security story with integrations across more than 40 other AWS services.&lt;/p&gt;

&lt;h4 id=&quot;how-secret-management-solutions-use-kms&quot;&gt;How Secret Management Solutions use KMS&lt;/h4&gt;

&lt;p&gt;As far as the options for secret management, each will eventually invoke the KMS APIs to do the same two things&lt;sup id=&quot;fnref:2&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Send the plaintext secret provide by the user to the KMS Encrypt API to get an encrypted secret back for storage.&lt;/li&gt;
  &lt;li&gt;Send the stored encrypted secret to the KMS Decrypt API to return the decrypted secret back to the authorized caller.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In addition, all communication with KMS is fully encrypted in transit.  The security risks in serverless secret management aren’t going to be with KMS directly, they are going to be how the secrets are managed when they have been decrypted as part of the deployment or runtime process.  Let’s look at how Lambda, Parameter Store, and Secrets Manager can be used and misused for secret management.&lt;/p&gt;

&lt;h3 id=&quot;lambda-environment-variables-with-plaintext-secrets&quot;&gt;Lambda Environment Variables with Plaintext Secrets&lt;/h3&gt;
&lt;p&gt;Lambda provides out-of-the-box functionality for specifying Environment Variables at deploy time that become available to the Lambda at invocation. Lambda environment variables are always encrypted via KMS while at rest within the AWS data centers.  However, there is gap: There is no out-of-the-box way to ensure the secrets are encrypted while in transit during deployment of the Lambda function.&lt;/p&gt;

&lt;p&gt;Here is a simple &lt;code class=&quot;highlighter-rouge&quot;&gt;serverless.yml&lt;/code&gt; definition via Serverless Framework using environment variables:&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;deploytime-env-var-function&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#NOT RECOMMENDED&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;envvar.handler&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; 
      &lt;span class=&quot;na&quot;&gt;SECRETKEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;${env:SECRETKEY}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is a common scenario where the secret is stored in the “secure environment variable” section of the CI provider or the developer machine.  At &lt;code class=&quot;highlighter-rouge&quot;&gt;serverless deploy&lt;/code&gt; time Serverless Framework will retrieve the secret via &lt;code class=&quot;highlighter-rouge&quot;&gt;${env:SECRETKEY}&lt;/code&gt; and then inject that secret into the Environment section of the auto-generated CloudFormation template used for ultimately deploying the Lambda.  That right there is already has some reason for concern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CloudFormation is not a good place for secrets.&lt;/strong&gt;  CloudFormation is not stored at rest with KMS encryption at either the origin machine or the destination AWS data center.  This breaks our first security goal of &lt;em&gt;always&lt;/em&gt; having secrets encrypted at rest.&lt;/p&gt;

&lt;p&gt;It is possible to deploy Lambdas by other means besides CloudFormation, either by invoking the Lambda APIs or using the Lambda UI in the AWS Console.  However, these alternative forms of Lambda deployment are also not recommended with plain text secrets as explained by &lt;a href=&quot;https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html#env_encrypt&quot;&gt;these AWS docs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;All the environment variables you’ve specified are encrypted by default after, but not during, the deployment process… If you need to store sensitive information in an environment variable, we strongly suggest you encrypt that information before deploying your Lambda function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;AWS isn’t making any promises that it keeps the environment variables secure at deploy time no matter which deployment method is used.&lt;/p&gt;

&lt;p&gt;Summary of specifying plaintext secrets as Lambda Environment Variables:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; No, due to CloudFormation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; No, due to AWS admitting they aren’t doing it within the datacenter.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; High&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: No additional cost&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;lambda-environment-variables-with-ciphertext-secrets&quot;&gt;Lambda Environment Variables with Ciphertext Secrets&lt;/h3&gt;

&lt;p&gt;As noted in the excerpt from the AWS docs above, Lambda does make a suggestion on how to store secrets: Encrypt them &lt;em&gt;before&lt;/em&gt; putting them in the Environment Variables.  From within the Lambda UI in the AWS Console, there are even helpers to encrypt the secret using KMS so the environment variable stores encrypted ciphertext.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/env-vars.png&quot; alt=&quot;Lambda Env Var helpers&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The helpers then provides an autogenerated code snippet that can be copy/pasted into the application to decrypt the secret at run time.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/kms-snippet.png&quot; alt=&quot;Lambda KMS Code Snippet&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Although it’s not practical to be using the Lambda UI for any sizable project for secret storage, it is possible to do the same approach in Serverless Framework by doing the KMS encryption manually and then store the ciphertext in the Environment Variables.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;deploytime-env-var-function&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; 
    &lt;span class=&quot;na&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;envvar_encrypted.handler&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;ENCRYPTED_SECRETKEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;AQICAHh429eYwvaw/MRcoBXJA3ZIzfZyHO5u4cZeDSlMNJdN8wFvQCBWjyFPWzzHsOXPiKxCAAAAZjBkBgkqhkiG9w0BBwagVzBVAgEAMFAGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQM1M3h1hp78u5K+0nNAgEQgCPyGN2+YTfb+G9bwnGRCQx0v+MaqNrhKoXOp+8J3tYhnyZFDQ==.&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;## Generated by calling KMS Encrypt API&lt;/span&gt;

    &lt;span class=&quot;na&quot;&gt;iamRoleStatements&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;## Give Lambda permission to call KMS Decrypt at run time.&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Effect&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Allow&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Action&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kms:Decrypt'&lt;/span&gt; 
        &lt;span class=&quot;na&quot;&gt;Resource&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;!GetAtt&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ServerlessDemoKey.Arn&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;boto3&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;base64&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kms_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boto3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'kms'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CiphertextBlob&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Plaintext'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kms_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ENCRYPTED_SECRETKEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Summary of specifying ciphertext secrets as Lambda Environment Variables:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; Medium&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: Low ($1/mo for Custom KMS key)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although this meets all the security requirements, it does lacks in usability.  It can be difficult for an authorized user to manage the plaintext of the secrets by needing to manually deal with KMS encryption/decryption each time the secret needs to be viewed or updated.&lt;/p&gt;

&lt;h3 id=&quot;parameter-store&quot;&gt;Parameter Store&lt;/h3&gt;

&lt;p&gt;AWS Systems Manager (SSM) has a hidden gem of a service called &lt;em&gt;Parameter Store&lt;/em&gt;.  Within Parameter Store you can store hierarchical configuration data and secrets for your application.  Each secret stored in Parameter Store is securely encrypted using KMS and can then be selectively shared with other AWS resources via IAM policies and APIs.  The service handles all the KMS operations for you so you never have to deal with ciphertext directly but can just reference the hierarchical path of the secret.&lt;/p&gt;

&lt;p&gt;Parameter Store has other nice benefits like providing a very useful history view showing all previous values, when the value was modified, and by whom.  And to top it off, Parameter Store is free to use.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/parameter-store.png&quot; alt=&quot;AWS Parameter Store&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It’s a great way to store secrets but there are many ways to get it wrong when using in a Serverless context.&lt;/p&gt;

&lt;h4 id=&quot;retrieve-decrypted-parameter-store-secrets-at-deploy-time&quot;&gt;Retrieve Decrypted Parameter Store Secrets at Deploy Time&lt;/h4&gt;
&lt;p&gt;Serverless Framework has built-in support for &lt;a href=&quot;https://serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-using-the-ssm-parameter-store&quot;&gt;Referencing Variables using the SSM Parameter Store&lt;/a&gt;.  To decrypt the values at deploy time specifying a &lt;code class=&quot;highlighter-rouge&quot;&gt;~true&lt;/code&gt; at the end of the key will get the plaintext value of the secret for deploying to Lambda.  However, this is NOT recommended for the same reasons as stated in Environment Variables section.  Since the secret is being decrypted at deploy time it is going to be shoved into CloudFormation in plaintext.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;deploytime-parameter-store&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# NOT RECOMMENDED&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;envvar.handler&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;SECRETKEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;${ssm:/my/path/to/secretkey~true}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Unfortunately, this is a recommended way of storing secrets on the &lt;a href=&quot;https://serverless.com/blog/serverless-secrets-api-keys/&quot;&gt;serverless blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Summary of Retrieving Decrypted Parameter Store Secrets at Deploy Time:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; No&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; No&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; High&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: No additional cost if using default KMS key&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;retrieve-encrypted-parameter-store-secrets-at-deploy-time&quot;&gt;Retrieve Encrypted Parameter Store Secrets at Deploy Time&lt;/h4&gt;

&lt;p&gt;This approach is similar to using using Environment Variables with Ciphertext Secrets talked about earlier.  The benefit here is that you can utilize the Parameter Store to easily view/manage and update your secrets.  In Serverless framework when  specifying &lt;code class=&quot;highlighter-rouge&quot;&gt;~false&lt;/code&gt; at the end of the &lt;code class=&quot;highlighter-rouge&quot;&gt;ssm&lt;/code&gt; key, or omitting the flag altogether, the secret will be retrieved from Parameter Store encrypted which will satisfy our encryption requirements.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;runtime-parameter-store&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;kms.handler&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;ENCRYPTED_SECRETKEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;${ssm:/my/path/to/secretkey~false}&quot;&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;SECRETKEY_ARN&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;arn:aws:ssm:${self:provider.region}:920535593515:parameter/my/path/to/secretkey&quot;&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# Will explain this..&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;iamRoleStatements&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;## Give Lambda permission to call KMS Decrypt at run time.&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Effect&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Allow&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Action&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kms:Decrypt'&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Resource&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;!GetAtt&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ServerlessDemoKey.Arn&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;boto3&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;base64&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;kms_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boto3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'kms'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CiphertextBlob&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EncryptionContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;PARAMETER_ARN&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Plaintext'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kms_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ENCRYPTED_SECRETKEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SECRETKEY_ARN'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;OK&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As long as the Parameter Store was configured to use the same KMS key for encrypting the secrets, the Lambda should be able to decrypt the values at runtime.&lt;/p&gt;

&lt;p&gt;This wouldn’t be too bad of an approach, but there is one obscure detail that makes this difficult.  When encrypting something using KMS there is an optional argument that can be specified called “Encryption Context” that consists of arbitrary key/values.  Parameter Store happens to internally call the KMS encrypt APIs using the Encryption  Context of:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{&quot;PARAMETER_ARN&quot;: &amp;lt;full parameter store arn of the secret being stored&amp;gt;})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now here is the tricky thing,  in order to decrypt the secret via KMS, the &lt;em&gt;same&lt;/em&gt; encryption context must be supplied.  So for each secret, the ARN of the secret in parameter store must be supplied in addition to knowing the path to the secret.&lt;/p&gt;

&lt;p&gt;Summary of Retrieving Encrypted Parameter Store Secrets at Deploy Time:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; Low&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: No additional cost if using default KMS key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although this is secure, the benefits of using Parameter Store in this way are offset by the complexity of passing in the custom encryption context.&lt;/p&gt;

&lt;h4 id=&quot;retrieve-parameter-store-secrets-at-runtime&quot;&gt;Retrieve Parameter Store Secrets at Runtime&lt;/h4&gt;
&lt;p&gt;It’s possible to just leverage Parameter Store Decryption directly within the application code at runtime only.  This removes the need to know of the secrets ARN as Parameter Store will handle all the KMS decryption for you when the lambda is invoked.  The Lambda function will just need IAM permissions to both get the parameter from Parameter Store and decrypt the value using KMS.  In this example the environment variable to be passed into the application is just the Parameter Store path to lookup.&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;na&quot;&gt;runtime-get-parameter-store&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;parameterstore.handler&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;SSM_PATH_TO_SECRETKEY&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/my/path/to/secretkey&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;iamRoleStatements&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt;  
        &lt;span class=&quot;na&quot;&gt;Effect&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Allow&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Action&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ssm:GetParameter&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Resource&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;arn:aws:ssm:${self:provider.region}:*:parameter/my/path/to/secretkey'&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Effect&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Allow&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Action&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
          &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;kms:Decrypt'&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;Resource&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;!GetAtt&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;ServerlessDemoKey.Arn&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;boto3&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;parameter_store_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boto3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ssm'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_parameter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;WithDecryption&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Parameter'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Value'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parameter_store_decrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'SSM_PATH_TO_SECRETKEY'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This solution supports all the security requirements as the Lambda is never deployed with the raw secrets.&lt;/p&gt;

&lt;p&gt;There is some complexity in the ease of use however with any run time retrieval of secrets that isn’t reflected in the sample code above. Should the secret be stored in the global scope to minimize API calls/latency when the Lambda is warm?  If so, how to invalidate the cached secret when it changes?&lt;/p&gt;

&lt;p&gt;Summary of Retrieving Parameter Store Secrets at Runtime&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; Medium&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: No additional cost if using default KMS key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is another nice feature about Parameter Store in that it is possible to call the &lt;code class=&quot;highlighter-rouge&quot;&gt;get_parameters&lt;/code&gt;  (note the plural) API to get &lt;em&gt;multiple&lt;/em&gt; configuration values/secrets in one API call based on the hierarchical Parameter Store path.   This can be useful in optimizing for cold boots.&lt;/p&gt;

&lt;h3 id=&quot;secrets-manager&quot;&gt;Secrets Manager&lt;/h3&gt;

&lt;p&gt;AWS Secrets Manager is yet another way to store secrets in the AWS ecosystem.  Secrets Manager has one primary benefit over Parameter Store: Auto rotation of RDS credentials.  If using RDS, Secrets Manager is a great  choice.  The nice thing about Secrets Manager is that it can be retrieved using the same SSM &lt;code class=&quot;highlighter-rouge&quot;&gt;get_parameter&lt;/code&gt; API despite being a separate service:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boto3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ssm'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_parameter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/aws/reference/secretsmanager/DBPass&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;WithDecryption&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are some downsides to Secrets Manager:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;It costs money per secret stored &lt;em&gt;and&lt;/em&gt; there is cost per retrieval of the secret.  This can add up in a serverless context when the secrets need to be retrieved on each lambda invocation.&lt;/li&gt;
  &lt;li&gt;There is no audit log to show previous values of secrets and when they were changed in the AWS Console.&lt;/li&gt;
  &lt;li&gt;It’s possible to only retrieve a single secret at a time.  In a cold start optimization context this can be impactful if there are multiple secrets.  (&lt;em&gt;&lt;strong&gt;Update&lt;/strong&gt;: It is possible to store multiple key/value pairs within a single Secret Manager secret to  get all secrets via a single call&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Secrets Manager is a relatively new service, so there may be new functionality to leverage as time goes on.&lt;/p&gt;

&lt;p&gt;Summary of Retrieving Parameter Store Secrets at Runtime&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted at Rest:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Always Encrypted in Transit:&lt;/strong&gt; Yes&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Ease of Use:&lt;/strong&gt; Medium&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Pricing&lt;/strong&gt;: Medium ($.40/secret, $.05/10000 API calls)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Solution&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Encrypted at Rest&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Encrypted in Transit&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Ease of Use&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Pricing&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Deploy Time: Env Var w/ Plaintext&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;No, not via CloudFormation&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;No, not within AWS&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Free w/ default KMS CMK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Deploy Time: Env Var w/ manual KMS Ciphertext&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Medium&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;$1/mo for KMS CMK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Deploy Time: Env Var w/ Plaintext from Parameter Store&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;No, not via CloudFormation&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;No, not within AWS&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;High&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Free w/ default KMS CMK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Deploy Time: Env Var w/ Ciphertext from Parameter Store&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Low&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;$1/mo for KMS CMK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Run Time: Parameter Store&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Medium&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Free w/ default KMS CMK&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Run Time: Secret Manager&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Medium&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;$.40/secret, $.05/10000 API calls&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Although it may seem like using a secret management service at run time may seem like the best option at first, there are a number of other complications to consider with run time solutions:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;How to catch a malformed secret from breaking the application when it is updated in the service?&lt;/li&gt;
  &lt;li&gt;How to handle caching of the secret as to not invoke the secret management service API each time it is needed?&lt;/li&gt;
  &lt;li&gt;How to invalidate the cache when the secret is no longer valid?&lt;/li&gt;
  &lt;li&gt;How to backoff with appropriate jitter when there are interruptions in the availability of the secret management service?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These concerns are less of a problem for deploy time solutions as they can be validated through a CI/CD pipeline before going live.&lt;/p&gt;

&lt;p&gt;The ecosystem of secret management solutions for Lambda suffers from too many options that don’t all provide a very strong security story. It takes some careful consideration of the security goals specific to your application.  For deploy time secret retrieval, Lambda Environment Variables with ciphertext via KMS is a solid option.  For run time secret retrieval, SSM Parameter Store and Secrets Manager will both do the job with the former perhaps being a bit better suited for Lambda at this time.&lt;/p&gt;

&lt;p&gt;What do you use for Secrets Management?  What other considerations are there?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;All of the code samples in this post can be found at &lt;a href=&quot;https://github.com/piohhmy/serverless-secret-examples&quot;&gt;piohhmy/serverless-secret-examples&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;hr /&gt;
&lt;hr /&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;div class=&quot;footnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot;&gt;
      &lt;p&gt;&lt;a href=&quot;https://www.eetimes.com/document.asp?doc_id=1279619&quot;&gt;https://www.eetimes.com/document.asp?doc_id=1279619&lt;/a&gt; &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot;&gt;
      &lt;p&gt;AWS Secrets Manager actually does this slightly different, it uses &lt;a href=&quot;https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#enveloping&quot;&gt;Envelope Encryption&lt;/a&gt; to get a Data Key from KMS and then uses that Data Key for the secret encryption. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;</content><author><name></name></author><category term="aws" /><category term="serverless" /><category term="secrets" /><category term="security" /><summary type="html">Getting started securing secrets in AWS Lambda is confusing at best and downright frightening at worst. You are faced with understanding and comparing KMS, Parameter Store, Secrets Manager, and Secure Environment Variables. You need to consider whether you are going to be retrieving secrets at run time, deploy time or a hybrid. And when you do retrieve the secrets you also are faced with deciding on whether to retrieve them decrypted or encrypted for later manual decryption.</summary></entry><entry><title type="html">Serverless ETL For Data Analytics</title><link href="https://dannyvarner.com/2018/11/25/serverless-etl-for-analytics.html" rel="alternate" type="text/html" title="Serverless ETL For Data Analytics" /><published>2018-11-25T03:30:14+00:00</published><updated>2018-11-25T03:30:14+00:00</updated><id>https://dannyvarner.com/2018/11/25/serverless-etl-for-analytics</id><content type="html" xml:base="https://dannyvarner.com/2018/11/25/serverless-etl-for-analytics.html">&lt;p&gt;I recently started collecting data on
reservation events for Fire Lookout Towers booked via &lt;a href=&quot;https://recreation.gov&quot;&gt;Recreation.gov&lt;/a&gt; as part of my side project &lt;a href=&quot;https://towerscouter.com&quot;&gt;Tower Scouter&lt;/a&gt;. This
post explores my first attempts in using AWS Glue, Amazon Athena, and Amazon SageMaker services for a
fully managed ETL and analytics pipeline to really geek out on
fire lookout reservation trends and patterns.&lt;/p&gt;

&lt;h2 id=&quot;the-event-data&quot;&gt;The Event Data&lt;/h2&gt;

&lt;p&gt;I have a &lt;a href=&quot;https://dannyvarner.com/2017/04/14/severless-web-scraper.html&quot;&gt;Serverless Web Scraper&lt;/a&gt;
running that publishes an event to an S3 bucket every time there is a
addition or removal in availability for a lookout tower. A sample availability removal
event looks something like this:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2019-02-20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;parkId&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;234185&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;detected&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2018-10-17T05:11:23.003528+0:00&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;event&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;rm&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case, an availability on Feb 20, 2019 for &lt;a href=&quot;https://www.recreation.gov/camping/campgrounds/234185&quot;&gt;Drake Peak Lookout&lt;/a&gt; was removed (e.g. booked by a user) on Oct 17th, 2018.&lt;/p&gt;

&lt;p&gt;A sample availability addition change event looks like this:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2019-03-20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;parkId&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;72017&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;detected&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2018-09-20T23:51:22.727807+00:00&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;event&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;add&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this case on Sept 20, 2018 an availability for &lt;a href=&quot;https://www.recreation.gov/camping/campgrounds/233133&quot;&gt;Timber Butte Cabin&lt;/a&gt; became available for the night of March 20.   This is a very typical event as fire lookout towers become available on Recreation.gov six months in advance.&lt;/p&gt;

&lt;p&gt;For every detected change in availability a new S3 Object with this JSON is stored for future analytics.&lt;/p&gt;

&lt;h2 id=&quot;exploring-the-data-with-athena&quot;&gt;Exploring the Data with Athena&lt;/h2&gt;

&lt;p&gt;Amazon Athena provides a way to run interactive SQL queries on data stored in S3 without ever having
to provision a database. JSON is supported out of the box so
this is a perfect use case for Athena. This is all powered under the hood by the open source &lt;a href=&quot;https://prestodb.io/&quot;&gt;Presto&lt;/a&gt; project.&lt;/p&gt;

&lt;p&gt;Athena was easy to quick start: I entered the service in the AWS Console, pointed Athena to the S3 bucket where my analytics data resides, defined what the schema of my JSON looks like, and then tried running a &lt;code class=&quot;highlighter-rouge&quot;&gt;SELECT *&lt;/code&gt; statement but quickly ran into
2 issues.&lt;/p&gt;

&lt;h3 id=&quot;first-issue-timestamp-is-in-iso8601-format&quot;&gt;First Issue: Timestamp is in ISO8601 format&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;detected&lt;/code&gt; timestamp I’m storing in my event data is in ISO8601 format.  Why is that an issue?  Before you can write your first query with Athena, you must specify the schema of the data source specifying the expected keys and data types.  My initial attempt in defining the schema was to treat the &lt;code class=&quot;highlighter-rouge&quot;&gt;detected&lt;/code&gt; field as type &lt;code class=&quot;highlighter-rouge&quot;&gt;timestamp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/specify-types.png&quot; alt=&quot;Defining Databae Types&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately the timestamp format expected is in the Java SQL format of &lt;code class=&quot;highlighter-rouge&quot;&gt;yyyy-mm-dd hh:mm:ss&lt;/code&gt; not ISO8601 of &lt;code class=&quot;highlighter-rouge&quot;&gt;yyyy-mm-ddThh:mm:ss+00:00&lt;/code&gt;.  This resulted in runtime errors as the underlying Presto engine couldn’t cast my ISO8601 string to its internal timestamp type.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/timestamp-type-error.png&quot; alt=&quot;Type Error on timestamp field&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To get around this, I &lt;em&gt;could&lt;/em&gt; just treat the &lt;code class=&quot;highlighter-rouge&quot;&gt;detected&lt;/code&gt; type as a string. I could then  use &lt;code class=&quot;highlighter-rouge&quot;&gt;date_parse&lt;/code&gt; in my query as defined in the
&lt;a href=&quot;https://prestodb.io/docs/current/functions/datetime.html&quot;&gt;PrestoDB datetime
functions&lt;/a&gt; to convert the string to a timestamp at execution time. Although this works, it’s not an elegant solution to parse the date on each query.&lt;/p&gt;

&lt;h3 id=&quot;second-issue-multiple-identifiers-referencing-same-data&quot;&gt;Second Issue: Multiple identifiers referencing same data&lt;/h3&gt;

&lt;p&gt;Recreation.gov performed a major refresh to their website in early October 2018 which included a change to the identifier for all their campsites, cabins and fire lookout towers.  This identifier is what I store as the &lt;code class=&quot;highlighter-rouge&quot;&gt;parkId&lt;/code&gt; in the json event.  As a result of the change to identifiers, my historical S3 events now have two separate identifiers that reference the same lookout tower&lt;/p&gt;

&lt;p&gt;Rather than deal with both of these issues at SQL runtime, this can be cleaned up with an ETL (Extract, Transform, Load) process.&lt;/p&gt;

&lt;h2 id=&quot;etl-with-aws-glue&quot;&gt;ETL with AWS Glue&lt;/h2&gt;

&lt;p&gt;AWS Glue provides a fully managed ETL service.  In this case I’ll be using Glue to perform an ETL process to fix the 2 issues identified in my initial attempt of using Athena directly on my raw availability events.&lt;/p&gt;

&lt;h3 id=&quot;step-1-define-the-data-catalog&quot;&gt;Step 1: Define the Data Catalog&lt;/h3&gt;

&lt;p&gt;AWS uses the term “Data Catalog” to refer to the metadata about where your data resides and how it looks.  This Data Catalog is conveniently shared across AWS services, so if I setup a Data Catalog table in Glue, I’ll be able to see it and use it in Athena.  Actually, when I defined my JSON schema as part of the Athena wizard, it internally created a table in the Data Catalog.&lt;/p&gt;

&lt;p&gt;Since AWS Glue is the primary place to edit the Data Catalog, I decided to start fresh and create both a source and target table in the Data Catalog via Glue for the ETL process.&lt;/p&gt;

&lt;h4 id=&quot;defining-the-source-table&quot;&gt;Defining the Source Table&lt;/h4&gt;

&lt;p&gt;The source table is going to be used for the “Extract” portion of the ETL. The Glue wizard walks you through some simple steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Define the table name.&lt;/li&gt;
  &lt;li&gt;Define where the data exists. In this case, the existing S3 bucket where my analytics data resides.&lt;/li&gt;
  &lt;li&gt;Define what type of data it should expect.  In this case, JSON.&lt;/li&gt;
  &lt;li&gt;Define the schema of the data.  In this case, it’s the same as we defined in Athena, but I want to be sure to choose ‘string’ as the type for the ISO8601 &lt;code class=&quot;highlighter-rouge&quot;&gt;detected&lt;/code&gt; timestamp to not run into the same issue as we ran into earlier.  I’ll convert the string to the proper format to be parsed as a &lt;code class=&quot;highlighter-rouge&quot;&gt;timestamp&lt;/code&gt; in the “Transformation” step.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/assets/glue-source-schema.png&quot; alt=&quot;Defining the schema&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;defining-the-target-table&quot;&gt;Defining the Target Table&lt;/h4&gt;

&lt;p&gt;The target table is going to be used for the “Load” portion of the ETL, the final state of what I want the data to look like after transformation.  I’ll follow the same steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Define the table name.&lt;/li&gt;
  &lt;li&gt;Define where the data exists. I’ll create a new empty S3 bucket to store the transformed data.&lt;/li&gt;
  &lt;li&gt;Define what type of data it should expect.  I could specify an optimized format like Apache Parquet or Apache ORC that would enable Athena to churn through the data more efficiently. To keep things simple though, I’ll just stick with JSON.&lt;/li&gt;
  &lt;li&gt;Define the schema of the data.  I’ll take the opportunity to also rename some of the keys to be more descriptive, I’ll also be sure to set &lt;code class=&quot;highlighter-rouge&quot;&gt;detected&lt;/code&gt; as a timestamp as I’m expecting the transformation step will have changed the format to be in the Java SQL format.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;/assets/glue-destination-schema.png&quot; alt=&quot;Destination Table in Data Catalog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Every table created in the Data Catalog via Glue will automatically show up in in Athena as a data source.  If I were to query this table in Athena now I’d get zero results as there is no data in the S3 bucket that it points to.  The next step will be to write the ETL script that takes the Source Table (Extract), performs the cleanup (Transform), and Loads it into Target Table (Load).&lt;/p&gt;

&lt;h3 id=&quot;step-2-create-the-etl-script&quot;&gt;Step 2: Create The ETL Script&lt;/h3&gt;

&lt;p&gt;The first thing I attempted was to create the script using the AWS Glue wizard that’s available when creating a new “Job”.  This wizard allows you to select your language (Python or Scala), allows you to choose your data source and data target (which we already defined), and allows you to do some basic mapping of types. The mapping of types here use the AWS Glue ApplyMapping Class which is intelligent enough to convert the ISO8601 string to the timestamp type.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/apply-mapping.png&quot; alt=&quot;Apply Mapping Step in Job Wizard&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As the wizard finishes it will bring up a basic text editor to edit the Glue generated script.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/glue-script.png&quot; alt=&quot;Glue Generated Script&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This script will work out of the box to solve the first issue I wanted to tackle with the timestamp types.  However, I’ll need to do some manual tweaking to add the transformation for the second issue of having multiple identifiers for the same lookout tower.  At first I tried just editing the script and running the job to see if I could make it work.  This is NOT an efficient way to get the ETL script working as:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Running a job isn’t instantaneous.  The job is submitted to an internal queue, I found it took 5-10 minutes before my job got executed by Glue.&lt;/li&gt;
  &lt;li&gt;Running a job isn’t cheap.  Although jobs are billed by the second, there is a 10 minute minimum.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are like me and have a very high likelihood of introducing a syntax error with each line of code written, there are going to be MANY executions of the job until it is working as desired. Fortunately AWS Glue has a great built-in solution to avoid waiting 5-10 minutes for feedback and facing a bill for each syntax error. Let’s look at yet another service, Amazon SageMaker.&lt;/p&gt;

&lt;h3 id=&quot;step-3-modify-and-debug-the-script-with-sagemaker&quot;&gt;Step 3: Modify and Debug the Script with SageMaker&lt;/h3&gt;

&lt;p&gt;Amazon SageMaker provides multiple helpful tools for the data scientist.  The one that is of interest when writing Glue ETL scripts is the SageMaker service to spin up a cloud hosted Jupyter notebook that can seamlessly connect to the needed ETL resources.  What’s really slick is that Glue has a tight integration with SageMaker allowing the notebook to be created and connected to the data catalog tables all without leaving Glue itself.  Here’s how to do it:&lt;/p&gt;

&lt;h4 id=&quot;create-a-dev-endpoint&quot;&gt;Create a Dev Endpoint&lt;/h4&gt;

&lt;p&gt;Within Glue, there is an option to create a “Dev Endpoint”.  This Dev Endpoint will give access to the execution engine and the S3 data source that I’m using.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dev-endpoint.png&quot; alt=&quot;Dev Endpoint&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Creating an endpoint is just another click through wizard.  It provides some options for creating an SSH key for connecting to the endpoint from a local IDE or notebook and also an option for custom networking to access data sources within a VPC.  In this case I can skip creating an SSH key as I’ll be connecting to the endpoint via SageMaker and I can skip any custom networking and I’ll just be accessing data in S3 so I don’t need VPC access.&lt;/p&gt;

&lt;h4 id=&quot;create-the-sagemaker-notebook&quot;&gt;Create the SageMaker Notebook&lt;/h4&gt;

&lt;p&gt;Once the Dev Endpoint is created, there is an option to create a SageMaker Notebook and auto connect it to the Dev Endpoint.  Once the Notebook is created I now have a fully functional cloud Notebook to debug and test within.&lt;/p&gt;

&lt;h4 id=&quot;finish-the-script&quot;&gt;Finish the Script&lt;/h4&gt;

&lt;p&gt;Now that I had a fast feedback loop being in an interactive notebook, it was much more pleasant finishing the script.  I fixed the syntax errors, learned the intricacies of how to interact with Glue’s data structures and classes through trial and error, and finished the cleanup of my data.  This resulted in a functional and runnable script that fixed both of my initial data issues.&lt;/p&gt;

&lt;h3 id=&quot;step-4-trigger-the-etl-glue-job&quot;&gt;Step 4: Trigger the ETL Glue Job&lt;/h3&gt;

&lt;p&gt;I copied the script from the notebook into the original Glue Job I created in Step 2 and was now able to run the ETL job successfully. When finished, the S3 bucket defined in the target table of the data catalog was populated with ‘cleaned’ events.  Here is the same availability event as referenced earlier for a Timber Butte Cabin availability, now with a new parkId and a new format to to the detected timestamp string that can be interpreted as a datetime type by the internal deserialization library.&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;event_date&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2019-03-20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;campground_id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;233133&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;detected_ts&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2018-09-20 23:51:22.7278&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;event&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;add&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;step-5-run-athena-queries-on-the-transformed-data&quot;&gt;Step 5: Run Athena Queries on the Transformed Data&lt;/h3&gt;

&lt;p&gt;Jumping back into Athena at this point I’m ready to start running SQL queries.  Since the Data Catalog tables defined in Glue are shared across services, the new table is already ready for me to select in Athena that will use the new S3 bucket with the transformed data.&lt;/p&gt;

&lt;h4 id=&quot;one-weird-thing&quot;&gt;One Weird Thing&lt;/h4&gt;

&lt;p&gt;When I ran queries on the cleaned data, the &lt;code class=&quot;highlighter-rouge&quot;&gt;date&lt;/code&gt; field returned from the Athena SQL queries were just bonkers. Despite having properly formatted dates in the current year of 2018 I was seeing dates 100s of years into the future.  Bonkers.&lt;/p&gt;

&lt;p&gt;The fix?  Change the serde (serialization/deserialization) library in the data catalog table from the default of &lt;code class=&quot;highlighter-rouge&quot;&gt;org.openx.data.jsonserde.JsonSerDe&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;org.apache.hive.hcatalog.data.JsonSerDe&lt;/code&gt;.  For some weird reason, the default openx serde lib can’t properly read in dates from JSON files.  Ugh.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/weird-serde.png&quot; alt=&quot;Weird Serde behavior&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;With Glue and SageMaker I was able to create a simple ETL pipeline that cleaned up my raw analytics data stored in S3.  With the cleaned up data I could then use Athena to run interactive SQL queries on my data despite not having a running database.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/athena-datetime.png&quot; alt=&quot;Athena Datetime Query&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the end I paid $3.64 for the Glue ETL time and nothing for Athena execution time.  This could have further been reduced quite a bit if I had just created a SageMaker Notebook to debug my ETL script earlier avoiding the 10 minute minimum billing of submitting many buggy ETL jobs to Glue.&lt;/p&gt;

&lt;p&gt;As a hobbyist with side projects that are run out of my own pocket this is super exciting.  It  amazes me with how much can be done in AWS without needing to pay for a server running 24/7.&lt;/p&gt;</content><author><name></name></author><category term="aws" /><category term="data" /><category term="serverless" /><category term="analytics" /><summary type="html">I recently started collecting data on reservation events for Fire Lookout Towers booked via Recreation.gov as part of my side project Tower Scouter. This post explores my first attempts in using AWS Glue, Amazon Athena, and Amazon SageMaker services for a fully managed ETL and analytics pipeline to really geek out on fire lookout reservation trends and patterns.</summary></entry><entry><title type="html">7 Lessons In Writing UI Tests For iOS</title><link href="https://dannyvarner.com/2018/07/23/7-lessons-in-wriring-ui-tests-for-ios.html" rel="alternate" type="text/html" title="7 Lessons In Writing UI Tests For iOS" /><published>2018-07-23T21:30:14+00:00</published><updated>2018-07-23T21:30:14+00:00</updated><id>https://dannyvarner.com/2018/07/23/7-lessons-in-wriring-ui-tests-for-ios</id><content type="html" xml:base="https://dannyvarner.com/2018/07/23/7-lessons-in-wriring-ui-tests-for-ios.html">&lt;p&gt;I recently finished a project to automate the deployment of my iOS hobby app &lt;a href=&quot;https://weatherhunt.com&quot;&gt;Weather Hunt&lt;/a&gt; to the App Store with a CI pipeline. In the end it looks like this:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Check in the code.&lt;/li&gt;
  &lt;li&gt;Click ‘deploy’ in the CI pipeline after all the tests pass&lt;/li&gt;
  &lt;li&gt;Review and Submit the fully prepared update via App Store Connect.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Behind the scenes this is all possible through:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;XCUIApplication based test automation&lt;/li&gt;
  &lt;li&gt;Fastlane and its rich ecosystem of plugins&lt;/li&gt;
  &lt;li&gt;Gitlab CI (see my post on &lt;a href=&quot;https://dannyvarner.com/2017/09/23/gitlab-ci.html&quot;&gt;The Best CI&lt;/a&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this post let’s dive into &lt;em&gt;XCUIApplication based test automation.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;background-ui-testing-in-xcode&quot;&gt;Background: UI Testing in XCode&lt;/h2&gt;

&lt;p&gt;UI Tests in general are notoriously brittle.  UI Tests for iOS are no exception.  Actually, be prepared for your UI tests to be quite a bit more quirky and inconsistent than any other UI testing frameworks you have used in the past.&lt;/p&gt;

&lt;p&gt;Why bother with UI testing in iOS with its lackluster reputation?  Well, if you get it right:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It can be used to test your app across &lt;em&gt;all&lt;/em&gt; supported devices and resolutions saving significant amounts of manual testing time.&lt;/li&gt;
  &lt;li&gt;It can be used to auto-capture refreshed screenshots for display in the App Store as part of a CD pipeline.&lt;/li&gt;
  &lt;li&gt;It can catch inconsistencies that your unit tests won’t be able to catch.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Be careful though, because if you get this step wrong:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;It will significantly slow down your feedback cycle by adding painfully slow tests that take a &lt;em&gt;long&lt;/em&gt; time to execute across all supported device simulators.&lt;/li&gt;
  &lt;li&gt;The screenshots that are captured will be inconsistent across devices causing your App Store branding to look unprofessional.&lt;/li&gt;
  &lt;li&gt;You will be plagued with seemingly random build failures that will cause you and your team to lose trust in the CI pipeline all together.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I suffered through all of the above in my first attempt of comprehensive UI testing.  The following is a list of 7 lessons that I learned the hard way in pursuit of creating a set of solid UI tests that are a part of a CI/CD pipeline.&lt;/p&gt;

&lt;h2 id=&quot;lesson-1-dont-trust-the-record-ui-test-button&quot;&gt;Lesson 1: Don’t trust the Record UI Test button.&lt;/h2&gt;

&lt;p&gt;I heard about this magic button that will write your UI tests for you.  It is built right into XCode in the Debug panel when a UI Test file is open.  It looks like this.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-record-btn.png&quot; alt=&quot;Record button&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The theory is that it will launch the iOS simulator and then as you click and swipe around your app it will auto-capture all the events in a programatic way.&lt;/p&gt;

&lt;p&gt;This is my experience:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-record-error.png&quot; alt=&quot;Timeout error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This error usually happens after a couple of clicks. From here your only way to resume recording is to restart the record session.  Oops.&lt;/p&gt;

&lt;p&gt;If you do manage to get lucky and have the recorder run error-free, here is an example recording output:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;scrollViewsQuery&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scrollViews&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;scrollViewsQuery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;matching&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;boundBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;matching&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yikes. Good luck trying to decipher what is being tapped in the above code. While it may be worth experimenting with this magic button, I suggest you are better off writing the code yourself.&lt;/p&gt;

&lt;h2 id=&quot;lesson-2-add-accessibility-identifiers-to-explicitly-target-specific-elements&quot;&gt;Lesson 2: Add accessibility identifiers to explicitly target specific elements&lt;/h2&gt;

&lt;p&gt;To reliably target taps on UI elements in a readable manner you should take advantage of accessibility identifiers.  This can be done directly in the Identity Inspector on a storyboard:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-accessibility.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;By adding accessibility identifiers, it allows simple targeting of UI elements like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;XCUIApplication&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buttons&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;switchAnnotation&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is much easier to understand than the rather verbose and indirect output of the Record UI Test button.&lt;/p&gt;

&lt;h4 id=&quot;protip&quot;&gt;&lt;em&gt;PROTIP&lt;/em&gt;&lt;/h4&gt;

&lt;p&gt;To even further simplify your tests add an app specific extension to XCUIApplication like so:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;XCUIApplication&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;switchAnnotation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buttons&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;switchAnnotation&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now the same action in the test is as simple as:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;switchAnnotation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Thanks to &lt;a href=&quot;https://medium.com/@johnsundell/getting-started-with-xcode-ui-testing-in-swift-ac7b1f5101e5&quot;&gt;@johnsundel&lt;/a&gt; for this one&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;lesson-3-take-advantage-of-breakpoints-and-lldb&quot;&gt;Lesson 3: Take advantage of breakpoints and LLDB&lt;/h2&gt;

&lt;p&gt;One of the ongoing challenges of writing UI tests via XCUIApplication is coming up with the correct element queries to execute user actions programatically. At first I would litter the test cases with print statements of the &lt;code class=&quot;highlighter-rouge&quot;&gt;app.debugDescription()&lt;/code&gt; output.  This is a super helpful method that shows the complete tree of available elements currently viewable in the UI.&lt;/p&gt;

&lt;p&gt;The problem though with using print statements in the tests is that it requires you to have the upfront insight to place the debug statements in all the possible places you may want to inspect the view hierarchy.  If you forget one place then you need to stop the simulator, add the extra print, rebuild and retest. This is a rather slow feedback loop and you end up with tests that look like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;search&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;searchFields&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;debugDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;debugDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;typeText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;debugDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cells&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;boundBy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;debugDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Enter the LLDB debugger!  Swift has a powerful debugger built-in to XCode that allows you to dynamically inspect the view hierarchy at anytime.  Simply set a breakpoint and then use the LLDB &lt;code class=&quot;highlighter-rouge&quot;&gt;po&lt;/code&gt; (print object) command in the debug window to see what you want on the fly.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-po-command.png&quot; alt=&quot;lldb po command&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;protip-1&quot;&gt;&lt;em&gt;PROTIP&lt;/em&gt;&lt;/h4&gt;

&lt;p&gt;Add the Test Failure Breakpoint in the Breakpoints Navigator to enter in the debugger on any assertion failure.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-test-failure-breakpoint.png&quot; alt=&quot;XCode Test Failure Breakpoint&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;lesson-3-create-separate-scheme-to-only-run-ui-tests&quot;&gt;Lesson 3: Create separate scheme to only run UI Tests&lt;/h2&gt;

&lt;p&gt;I found a lot of time spent creating UI tests is just waiting.  Waiting for a rebuild. Waiting for the simulator. Waiting for the tests to run.  If there are ways to reduce this waiting it not only directly improves build times but also psychologically reduces the likelihood for developer context switching to another task out of boredom.&lt;/p&gt;

&lt;p&gt;One quick improvement is to create a dedicated scheme that &lt;em&gt;only&lt;/em&gt; runs UI tests.  By default, when clicking “Product-&amp;gt;Test” in XCode it will build and run both the Unit Test suite and the UI Test suite.&lt;/p&gt;

&lt;p&gt;To create a custom scheme go to Product -&amp;gt; Manage Schemes and duplicate the default Scheme.  Open the duplicated scheme. Under the Test panel you’ll see the multiple test targets for your unit tests and UI tests.  Remove the Unit Tests and name the scheme something like ‘UI Tests’.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-manage-schemes.png&quot; alt=&quot;Manage Schemes&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now when you want to run &lt;em&gt;only&lt;/em&gt; your UI Tests just select the newly created scheme and hit play.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-uitest-scheme.png&quot; alt=&quot;Select Unit Test Scheme&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;lesson-4-explicitly-wait-for-everything&quot;&gt;Lesson 4: Explicitly wait for everything&lt;/h2&gt;

&lt;p&gt;After performing an action in a UI Test, XCUIApplication will automatically wait for the app to ‘idle’ before continuing with the next action.  This is to allow time for the animations and new views to properly load before starting the next action.  The problem is that this wait time is all magic and can lead to some periodic build failures if it doesn’t get it right.&lt;/p&gt;

&lt;p&gt;Explicitly waiting for each new view to become visible can avoid these errors. This can be done with the &lt;code class=&quot;highlighter-rouge&quot;&gt;waitForExistance&lt;/code&gt; method on an XCUIElement. Here is an example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;search&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;searchFields&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;tap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;XCTAssert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keyboards&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;firstMatch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;waitForExistence&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;typeText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;my search&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this example after tapping search, we explicitly wait for the keyboard to show up before typing.&lt;/p&gt;

&lt;h2 id=&quot;lesson-6-use-the-macos-accessibility-inspector&quot;&gt;Lesson 6: Use the macOS Accessibility Inspector&lt;/h2&gt;

&lt;p&gt;The Accessibility Inspector is a built-in tool on macOS that allows viewing all the accessibility properties and actions for any running application.  Since the XCUIApplication depends on programmatically navigating the application with many of the accessibility features this can be a really useful debugging tool.&lt;/p&gt;

&lt;p&gt;This proved particularly useful when I was debugging a UI test attempting to create multiple annotations on a map.  This test case would take the center coordinate of an existing annotation, add an offset to the coordinate, and then use that new coordinate to create a second annotation.  The problem was the second annotation wasn’t showing up in the expected location.  By using the Accessibility Inspector I was able to quickly see that the bounding box for the Annotation View was inherently wrong.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/xcode-accessibility-inspector.png&quot; alt=&quot;Accessibility Inspector&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;lesson-7-dont-expect-swipes-to-be-consistent&quot;&gt;Lesson 7: Don’t expect swipes to be consistent&lt;/h2&gt;

&lt;p&gt;Unfortunately, I don’t have a great tip here.  There is no way I’ve found to make the velocity of the swipe gestures (e.g. &lt;code class=&quot;highlighter-rouge&quot;&gt;swipeLeft()&lt;/code&gt;) deterministic in the simulator.  Most of the time this is probably fine, but in an app where the velocity of a swipe matters (e.g. in panning a map to a new location) the best bet is to avoid this action in the tests if possible.&lt;/p&gt;

&lt;h2 id=&quot;wrapping-it-up&quot;&gt;Wrapping it up&lt;/h2&gt;

&lt;p&gt;Writing UI Tests for iOS has plenty of quirks.  By taking these lessons into consideration it is possible to create UI tests that run efficiently, are easy to debug, and produce consistent results.  Once the UI tests are in place it can provide a fully automated continuous deployment pipeline by automatically extracting screenshots to upload to the App Store. More on that in a future blog post.&lt;/p&gt;

&lt;p&gt;If you’ve written UI Tests for iOS in the past, what pain points have you encountered?  Do you have any other takeaways you wish you knew about before you started?&lt;/p&gt;</content><author><name></name></author><category term="ios" /><category term="ci" /><category term="swift" /><summary type="html">I recently finished a project to automate the deployment of my iOS hobby app Weather Hunt to the App Store with a CI pipeline. In the end it looks like this:</summary></entry><entry><title type="html">Behavioral Diversity Within Dysfunctional Processes</title><link href="https://dannyvarner.com/2018/04/26/behavioral-diversity-within-dysfunctional-processes.html" rel="alternate" type="text/html" title="Behavioral Diversity Within Dysfunctional Processes" /><published>2018-04-26T04:30:00+00:00</published><updated>2018-04-26T04:30:00+00:00</updated><id>https://dannyvarner.com/2018/04/26/behavioral-diversity-within-dysfunctional-processes</id><content type="html" xml:base="https://dannyvarner.com/2018/04/26/behavioral-diversity-within-dysfunctional-processes.html">&lt;p&gt;Diversity in teams is a good thing. I’ve been thinking about the 
diversity in behavioral tendencies that help to create a one-of-a-kind team
culture. Specifically, how does diversity play a role when encountering
dysfunctional processes in a software organization?&lt;/p&gt;

&lt;p&gt;There is no shortage of process and no shortage of dysfunction in software
organizations. This makes it rather easy to observe and make some
generalizations of behavior. Examples of common process dysfunctions in
software organizations:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Processes for how work is estimated, prioritized, and tracked&lt;/li&gt;
  &lt;li&gt;Processes for long range roadmap planning&lt;/li&gt;
  &lt;li&gt;Processes for handling of production incidents, customer requests, and bugs&lt;/li&gt;
  &lt;li&gt;Processes for releasing and deploying&lt;/li&gt;
  &lt;li&gt;Processes for interacting with external dependencies, like an ops team or a shared software component.&lt;/li&gt;
  &lt;li&gt;Processes for evaluating individual performance and merit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My own tendency when encountered with dysfunctional process is to
dive in and work to change the process. But I fully realize if everyone was focused on
changing process and getting buy in on new and better ways to work, we would
rarely ship actual code and the product would ultimately suffer. Diversity in
how a team reacts to dysfunctional process is healthy.&lt;/p&gt;

&lt;p&gt;Here are three tongue-in-cheek personas to demonstrate the
differences in behavioral tendencies when encountered with a dysfunctional process:&lt;/p&gt;

&lt;h2 id=&quot;the-wizard&quot;&gt;The Wizard&lt;/h2&gt;

&lt;p&gt;The wizard is able to magically get things done despite inefficiencies in the
process. When I think of a wizard in the fantastical sense they are reciting
ancient spells in obscure languages and everyone is amazed by what happens.
The modern day wizards know may know a programming language, a scripting
language, a tool, a library better than anyone on the team and can invoke its
magic when it is most needed. You know that guy who can solve any problem
with a bash prompt? Wizard. These personas are often the first to go to when
something goes wrong. The wizard accepts the constraints and dysfunctions of
the processes and gets stuff done despite it all.&lt;/p&gt;

&lt;h2 id=&quot;the-activist&quot;&gt;The Activist&lt;/h2&gt;

&lt;p&gt;The activist is championing a better way, a way free from the injustices of
past processes. A political activist makes loud statements through marches,
demonstrations, or social media in order to raise awareness to the issues at
hand. The software activist has similarly seen the light of what ‘best
practices’ can do to a team and is determined to bury old antiquated
processes. The activists is not afraid to break the process if it can prove a
point that there are better ways of working. With little reverence for the
processes in place the activist is able to build a better product by carving
new pathways quickly.&lt;/p&gt;

&lt;h2 id=&quot;the-diplomat&quot;&gt;The Diplomat&lt;/h2&gt;

&lt;p&gt;The diplomat is sensitive to the importance of understanding the underlying
motives that often lurk behind dysfunctional processes. Diplomats
in foreign policy are often found negotiating strategic agreements with
other states while representing the interests of the sending state to create
that ‘win-win’ agreement. In software teams the diplomat will be dialoging with
the internal team members to understand process constraint while also
reaching out to other stakeholders external to the team if there is an
opportunity to systematically influence process change. The diplomat seeks long lasting
improvements that can be made with healthy relationships and the constant perusal
of the underlying root causes in dysfunctional processes.&lt;/p&gt;

&lt;p&gt;Do you resonate with one of these personas? Is the team you work with a
mono-culture in behavioral tendencies or is it full of diversity? My team at
work is in the process of hiring, I wonder, how the interview process would
change if we sought out out candidates that have different behavioral
tendencies? Do I bias my evaluations of candidates based on my ‘diplomat’
tendencies?&lt;/p&gt;

&lt;p&gt;As a final note, I just want to recognize that it would be silly to say say
everyone fits into one of these personas. If you’re thinking “I don’t fit
into one of these..”, the point is not that you don’t fit in. Diversity takes
many forms. In fact, I’d love to come up with many more cheeky personas to
add to the mix. These personas are really just here to help me see the value
“the other” brings, to look at those different than myself and see how I rely
on them to be a more effective developer and agent for change.&lt;/p&gt;

&lt;p&gt;Here is a picture in the lobby of Wieden+Kennedy in Portland, OR. This text
sits among a large wall of all these individual and quirky photos of W+K
employees. Love this message.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/diversity.jpg&quot; alt=&quot;Diversity&quot; /&gt;&lt;/p&gt;</content><author><name></name></author><category term="diversity" /><category term="process" /><category term="team-dynamics" /><summary type="html">Diversity in teams is a good thing. I’ve been thinking about the diversity in behavioral tendencies that help to create a one-of-a-kind team culture. Specifically, how does diversity play a role when encountering dysfunctional processes in a software organization?</summary></entry><entry><title type="html">Forward Geocoding the Outdoors with Swift</title><link href="https://dannyvarner.com/2018/02/19/forward-geocoding-the-outdoors.html" rel="alternate" type="text/html" title="Forward Geocoding the Outdoors with Swift" /><published>2018-02-19T22:45:00+00:00</published><updated>2018-02-19T22:45:00+00:00</updated><id>https://dannyvarner.com/2018/02/19/forward-geocoding-the-outdoors</id><content type="html" xml:base="https://dannyvarner.com/2018/02/19/forward-geocoding-the-outdoors.html">&lt;p&gt;In contrast to the geotagged, Yelp rated, and Google streetviewed locations that cover populated areas, points of interest in the wild are very sparse in terms of accessible API data. Searches for trailheads, rivers, mountain peaks, climbing routes, swim holes all have wildly different results between the big geo-based API providers.&lt;/p&gt;

&lt;p&gt;I recently stayed at &lt;a href=&quot;https://www.recreation.gov/camping/fivemile-butte-lookout/r/campgroundDetails.do?contractCode=NRSO&amp;amp;parkId=75098&quot;&gt;Fivemile Butte Fire Lookout Tower&lt;/a&gt; on Mt Hood, Oregon.  The closest town is Dufur, OR some 20 miles away.  There is no address, just a forest service access road.   During the summer it’s possible to drive to up to the tower but in the winter it’s only accessible by snowshoe, ski or snowmobile.  Will the big geo APIs be able to find this place?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/fivemile-butte.jpg&quot; alt=&quot;Fivemile Lookout Tower&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;geocoding-overview&quot;&gt;Geocoding Overview&lt;/h2&gt;

&lt;p&gt;“Forward Geocoding” allows one to find the geographic coordinates from a human readable query string.  “Reverse Geocoding” allows one to find the name and details of a point of interest using only the geographic coordinates.  For this test I focused on the forward geocoding capabilities of Apple, Mapbox and Google to see how well they can find the Fivemile Butte Lookout.&lt;/p&gt;

&lt;h2 id=&quot;apple&quot;&gt;Apple&lt;/h2&gt;
&lt;p&gt;Apple doesn’t have a great reputation in the geospatial space, so expectations are low. The big advantages Apple provides to developers are&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;No external libraries/SDKs are necessary as everything is builtin to Mapkit, and&lt;/li&gt;
  &lt;li&gt;There are no throttle limits or extra cost to utilize the capabilities.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are two core MapKit APIs when searching for POIs: &lt;code class=&quot;highlighter-rouge&quot;&gt;MKLocalSearchRequest&lt;/code&gt; for complete string queries and &lt;code class=&quot;highlighter-rouge&quot;&gt;MKLocalSearchCompleter&lt;/code&gt; for partial string autocomplete functionality in search boxes.  We’ll used the former for the test.&lt;/p&gt;

&lt;h3 id=&quot;mapkit-mklocalsearch-api&quot;&gt;Mapkit MKLocalSearch API&lt;/h3&gt;
&lt;p&gt;The successful response of a &lt;code class=&quot;highlighter-rouge&quot;&gt;MKLocalSearchRequest&lt;/code&gt; execution will be a &lt;code class=&quot;highlighter-rouge&quot;&gt;MKMapItem&lt;/code&gt; object that includes coordinates and descriptions of the matching locality.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MapKit&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;searchReq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MKLocalSearchRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;searchReq&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;naturalLanguageQuery&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Fivemile Butte Lookout&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;search&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MKLocalSearch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;searchReq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;completionHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;items&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;resp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mapItems&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;no items found&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;items&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;placemark&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subAdministrativeArea&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;administrativeArea&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Result:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Butte Lookout Rd, Chelan, WA, United States
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;FAIL.&lt;/strong&gt; Butte Lookout Rd is definitely not what we’re looking for.&lt;/p&gt;

&lt;h2 id=&quot;mapbox&quot;&gt;Mapbox&lt;/h2&gt;
&lt;p&gt;Mapbox has beautiful maps for the outdoors that are fully customizable with topographic shading, contour lines, and named features on the map tiles themselves. &lt;a href=&quot;https://weatherhunt.com&quot;&gt;Weather Hunt&lt;/a&gt; already uses these fantastic maps. Is their forward geocoding API for the outdoors also great?  Let’s check it out.&lt;/p&gt;

&lt;h3 id=&quot;mapbox-forwardgeocoder-api&quot;&gt;Mapbox ForwardGeocoder API&lt;/h3&gt;
&lt;p&gt;Note, Mapbox limits their geocode requests to 50,000/mo on their free plan.&lt;/p&gt;
&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MapboxGeocoder&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;geocoder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Geocoder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;accessToken&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;my-secret-token&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;options&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ForwardGeocodeOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Fivemile Butte Lookout&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allowedISOCountryCodes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;US&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;  
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;geocoder&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;geocode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;placemarks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;attribution&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;placemarks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;placemarks&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;no items found&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;placemarks&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;administrativeRegion&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;            
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Results:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Fivemile, Texas, United States
Black Butte Lookout Drive, California, United States
Black Butte Lookout Road, California, United States
Black Butte Lookout Drive, California, United States
Horse Butte Lookout Road, Montana, United States
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;FAIL.&lt;/strong&gt;  Lots of “Buttes” but no lookout tower.&lt;/p&gt;

&lt;h2 id=&quot;google&quot;&gt;Google&lt;/h2&gt;
&lt;p&gt;Google enables developers to utilize their Places APIs with all of their forward geocoding capabilities and place data without requiring use of their Maps. Neat. The forward geocoding capabilities are disguised behind the &lt;code class=&quot;highlighter-rouge&quot;&gt;autocompleteQuery&lt;/code&gt; method of the &lt;code class=&quot;highlighter-rouge&quot;&gt;GMSPlacesClient&lt;/code&gt; class. It’s free to use for the first 150,000 requests/day.  Generous.  Let’s see how it works.&lt;/p&gt;

&lt;h3 id=&quot;google-gmsplacesclient-api&quot;&gt;Google GMSPlacesClient API&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GooglePlaces&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;GMSPlacesClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;provideAPIKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;api&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;placesClient&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GMSPlacesClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GMSAutocompleteFilter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;establishment&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;placesClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;autocompleteQuery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Fivemile Butte Lookout&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Autocomplete error &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attributedFullText&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Results:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Fivemile Butte Lookout Tower, Rail Hollow Road, Dufur, OR, USA
Fivemile Butte Lookout, Dufur Valley Rd, Dufur, OR, USA
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;SUCCESS.&lt;/strong&gt; We have our match in Dufur, OR.  Strange there are two matches for the same place, but that’s quite alright.  If I want, I can grab the &lt;code class=&quot;highlighter-rouge&quot;&gt;placeID&lt;/code&gt; from the result and use it to get additional data such as coordinates, photos, and more.&lt;/p&gt;

&lt;p&gt;This is just a first step of getting familiar with the geocoding capabilities of Apple, Mapbox, and Google.  Perhaps a next step will be to run a more robust test that includes a bigger dataset of lookout towers or trailheads or waterfalls to see how many are recognizable by each service. Also, we just looked at forward geocoding.  What about the reverse geocoding APIs from each?&lt;/p&gt;</content><author><name></name></author><category term="swift" /><category term="ios" /><category term="weatherhunt" /><category term="dev" /><category term="maps" /><summary type="html">In contrast to the geotagged, Yelp rated, and Google streetviewed locations that cover populated areas, points of interest in the wild are very sparse in terms of accessible API data. Searches for trailheads, rivers, mountain peaks, climbing routes, swim holes all have wildly different results between the big geo-based API providers.</summary></entry><entry><title type="html">Agile Camp NW 2017: Scaled Agile and DevOps</title><link href="https://dannyvarner.com/2017/09/29/scaled-agile-and-devops.html" rel="alternate" type="text/html" title="Agile Camp NW 2017: Scaled Agile and DevOps" /><published>2017-09-29T14:22:14+00:00</published><updated>2017-09-29T14:22:14+00:00</updated><id>https://dannyvarner.com/2017/09/29/scaled-agile-and-devops</id><content type="html" xml:base="https://dannyvarner.com/2017/09/29/scaled-agile-and-devops.html">&lt;p&gt;Agile Camp Northwest 2017 was held in early September at the Nike World Headquarters in Beaverton, OR.  There were a couple talks that really got me scribbling.  These are some takeaways from the talk &lt;em&gt;Scaled Agile and DevOps: Give Your DevOps Initiatives More Context by Leveraging Agile At Scale&lt;/em&gt; by Kathryn Kuhn (&lt;a href=&quot;https://schd.ws/hosted_files/agilecamppacificnorthwest2017/48/AgileCamp_DevOps.pdf&quot;&gt;Slides&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;highlights-from-the-talk&quot;&gt;Highlights from the Talk&lt;/h2&gt;
&lt;p&gt;The talk focused on how Agile and DevOps transformations really need to happen together.  Both agile and DevOps are grounded in many of the same Lean principles: small batch size, limit WIP, continuous improvement, and both have a strong emphasis on the need to connect strategy and business value.  Here are the top four concepts that really stuck with me after the talk.&lt;/p&gt;

&lt;h3 id=&quot;the-goal-business-agility&quot;&gt;The Goal: Business Agility&lt;/h3&gt;
&lt;p&gt;The “Goal” of agile and DevOps transformations could be defined as Business Agility: an enterprises ability to sense and respond to change quickly and confidently as a matter of everyday business.  Contrast this to a ‘squirrel’ mentality where one is constantly chasing and changing direction.  Another way to think about it is that business agility through agile and DevOps transformations enable ‘calculated’ change over ‘spurious and disruptive’ change.&lt;/p&gt;

&lt;p&gt;An interesting metric for measuring business agility that I gleaned from the talk is to measure the ‘wake’ when change is made.  How much disruption, confusion, loss of productivity, and angst is caused by changing direction?   It is one thing to celebrate a new feature, rearchitecture or process improvement made in record time, but what was the cost of focusing everyone’s attention on it? Did other priorities fall off? Did morale take a hit? Did technical debt accumulate?  Being able to rapidly shift and not cause large wakes is a sign of a mature organization/team.&lt;/p&gt;

&lt;p&gt;How can a organization improve its business agility?  A couple of key points:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Adaptive planning is needed for Agile and DevOps transformations over sequential, phase gate planning&lt;/li&gt;
  &lt;li&gt;Focus on achieving the shortest possible lead time&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;gemba-walk-the-real-place&quot;&gt;Gemba Walk: The Real Place&lt;/h3&gt;
&lt;p&gt;The Gemba Walk, a part of Lean management philosophy, was shown to be an excellent first step (and ongoing habit) in understanding the problems that exist in an organization striving for business agility. Gemba comes from the Japanese term meaning “the real place”.  It involves going to see the actual process, understanding the work, asking questions, and learning from the people involved in actually producing the value.&lt;/p&gt;

&lt;p&gt;What I really appreciate about a Gemba is that there is an emphasis on questions rather than answers when identifying improvement opportunities.  There is an investment in getting dirty on the ground rather than the observing from the ivory tower.&lt;/p&gt;

&lt;p&gt;A good example of what I’d consider a “Gemba walk” came from another unrelated talk at Agile Camp.  Mamie Jones, the Sr. Vice President of Product Development at Intuit gave a fantastic talk on &lt;em&gt;Leading Tranfomrational Change&lt;/em&gt; (&lt;a href=&quot;https://schd.ws/hosted_files/agilecamppacificnorthwest2017/de/Nike%202017%20Agile%20Camp%20Final_Mamie.pdf&quot;&gt;Slides&lt;/a&gt;).  As a new leader coming into a dysfunctional organization she sat down with all the people involved in the value stream (100s of people) and asked a simple set of questions before starting any improvement work in the organization.  This type of curiosity and desire to understand problems is a quality that I aspire to as an agile coach or scrum master.&lt;/p&gt;

&lt;h3 id=&quot;maturity-models&quot;&gt;Maturity Models&lt;/h3&gt;
&lt;p&gt;One topic in the talk that caused some healthy head scratching was the speaker’s general dissatisfaction on agile ‘maturity models’.  The alternative was to focus on ‘capability models’ instead.  The capability model referenced in the talk is called &lt;a href=&quot;https://devops-research.com/&quot;&gt;DORA: DevOps Research &amp;amp; Assessment&lt;/a&gt;.  The DORA is only available through a consultancy at $40K for a company analysis, so it raises some flags.  How is a ‘capability model’ better than ‘maturity model’, or really how they are all that different?  I’m still not sure, but my takeaway is that with any metric or model, they can be abused.  When looking at adopting a maturity or capability  model to evaluate team or organizational health, care must be taken. The metrics shouldn’t be used to compare or reward teams as this will cause the metrics to be gamed and manipulated.&lt;/p&gt;

&lt;p&gt;Another key takeaway that hasn’t occurred to me is to be weary of ‘reaching the ceiling’ in maturity models.  For instance, if you reach the top tier in a maturity model, does that mean you are done and there is no room for improvement?  I find maturity models to be a useful tool as a starting place to identify growth opportunities and for teams to aspire to greater technical and process health, though it is good to also recognize there are dangers in overemphasizing the model.&lt;/p&gt;

&lt;h3 id=&quot;agile-and-devops-together-horse-shoe-diagram&quot;&gt;Agile and DevOps Together: Horse Shoe Diagram&lt;/h3&gt;
&lt;p&gt;The final piece inspiring piece I want to share from the talk was the speaker’s “Horse Shoe” diagram for visualizing the product lifecycle with an Agile and DevOps focused culture. There’s a few things I love about this diagram:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;It shows that the traditional Product Lifecycle stages are really no different than Agile/DevOps Product Lifecycle stages. The lifecycle is there to take a concept and turn it into money. The obvious difference with the Agile/DevOps Product Lifecycle is that it minimizes the cycle time through automation, autonomy, lightweight process, and strong engineering/quality practices.&lt;/li&gt;
  &lt;li&gt;It shows that Agile and DevOps practices need to be developed in tandem to realize a true business agility.&lt;/li&gt;
  &lt;li&gt;There is emphasis on measurable outcomes.  A Goal or hypothesis should be defined up front.  As the concept moves quickly through the stages of agile an DevOps lifecyle reaching a production environment there is then the opportunity to inspect and adapt. &lt;br /&gt;
&lt;img src=&quot;/assets/horseshoe.png&quot; alt=&quot;Horseshoe Diagram&quot; /&gt;
&lt;em&gt;credit: Kathryn Kuhn&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Kudos to Kathryn for delivering a great talk that has left me pondering over the last month on how to better scale agile and DevOps in unison.  Also, kudos to the organizers of Agile Camp.  It’s nice attending a single day conference, as it leaves space for material to be absorbed versus being overwhelmed and drained with far too much information over multiple days.  I’d like to write up another post on another fantastic talk by Kevin Goldsmith, CTO at Avvo titled &lt;em&gt;Creating a culture of continuous improvement in your company&lt;/em&gt;.  Stay tuned.&lt;/p&gt;</content><author><name></name></author><category term="agile" /><category term="devops" /><category term="conference" /><summary type="html">Agile Camp Northwest 2017 was held in early September at the Nike World Headquarters in Beaverton, OR. There were a couple talks that really got me scribbling. These are some takeaways from the talk Scaled Agile and DevOps: Give Your DevOps Initiatives More Context by Leveraging Agile At Scale by Kathryn Kuhn (Slides)</summary></entry><entry><title type="html">Artisanal File Transfers with Netcat</title><link href="https://dannyvarner.com/2017/09/28/netcat-transfer.html" rel="alternate" type="text/html" title="Artisanal File Transfers with Netcat" /><published>2017-09-28T01:22:14+00:00</published><updated>2017-09-28T01:22:14+00:00</updated><id>https://dannyvarner.com/2017/09/28/netcat-transfer</id><content type="html" xml:base="https://dannyvarner.com/2017/09/28/netcat-transfer.html">&lt;p&gt;It’s 2017 and when two devs sitting next to each other are confronted with the task of transferring a giant bulky file from one laptop to another, the stress in the room rips. Why is this so hard? I found myself in this situation recently when my coworker suggested we try netcat.  With full skepticism on how an ancient unix tool can possibly be an acceptable answer with all the airdropping, cloud syncing, and transfer-a-file-as-a-service options out there, I agreed to give it a shot.&lt;/p&gt;

&lt;p&gt;It worked great.&lt;/p&gt;

&lt;h2 id=&quot;how-to-netcat-a-file-to-your-coworker&quot;&gt;How to Netcat a File to Your Coworker&lt;/h2&gt;

&lt;h3 id=&quot;destination-computer&quot;&gt;Destination Computer&lt;/h3&gt;

&lt;p&gt;Start listening&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# macOS&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;nc &lt;span class=&quot;nt&quot;&gt;-l&lt;/span&gt; 1234 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; myfile

&lt;span class=&quot;c&quot;&gt;# Anything else, or brew installed netcat&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;nc &lt;span class=&quot;nt&quot;&gt;-l&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 1234 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; myfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Also, you’ll want your IP&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# macOS&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ifconfig en0 inet
en0: &lt;span class=&quot;nv&quot;&gt;flags&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8863&amp;lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&amp;gt; mtu 1500
 inet 192.168.0.28 netmask 0xffffff00 broadcast 192.168.0.255
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;source-computer&quot;&gt;Source Computer&lt;/h3&gt;

&lt;p&gt;Trigger the transfer&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat &lt;/span&gt;myfile | nc 192.168.0.28 1234
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;see-it-in-action&quot;&gt;See it in action&lt;/h3&gt;

&lt;p&gt;Here I’ll transfer my plans for a taco truck to my coworker Frank.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Frank’s Shell&lt;/em&gt;:
&lt;script type=&quot;text/javascript&quot; src=&quot;https://asciinema.org/a/mqXQuTHIYVJYGUHLEcHxe0pJG.js&quot; id=&quot;asciicast-mqXQuTHIYVJYGUHLEcHxe0pJG&quot; async=&quot;&quot; data-autoplay=&quot;true&quot; data-loop=&quot;false&quot; data-rows=&quot;11&quot; data-cols=&quot;100&quot; data-speed=&quot;2&quot; data-theme=&quot;tango&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;My Shell&lt;/em&gt;:
&lt;script type=&quot;text/javascript&quot; src=&quot;https://asciinema.org/a/80hWpQb7vKcNfTfABuz1sHVxA.js&quot; id=&quot;asciicast-80hWpQb7vKcNfTfABuz1sHVxA&quot; async=&quot;&quot; data-autoplay=&quot;true&quot; data-loop=&quot;false&quot; data-rows=&quot;3&quot; data-cols=&quot;100&quot; data-speed=&quot;2&quot; data-theme=&quot;asciinema&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Bam.  Taco plans delivered.  And now I’m getting hungry.&lt;/p&gt;</content><author><name></name></author><category term="dev" /><category term="bash" /><summary type="html">It’s 2017 and when two devs sitting next to each other are confronted with the task of transferring a giant bulky file from one laptop to another, the stress in the room rips. Why is this so hard? I found myself in this situation recently when my coworker suggested we try netcat. With full skepticism on how an ancient unix tool can possibly be an acceptable answer with all the airdropping, cloud syncing, and transfer-a-file-as-a-service options out there, I agreed to give it a shot.</summary></entry><entry><title type="html">GitLab: The best CI you haven’t used</title><link href="https://dannyvarner.com/2017/09/23/gitlab-ci.html" rel="alternate" type="text/html" title="GitLab: The best CI you haven't used" /><published>2017-09-23T18:22:14+00:00</published><updated>2017-09-23T18:22:14+00:00</updated><id>https://dannyvarner.com/2017/09/23/gitlab-ci</id><content type="html" xml:base="https://dannyvarner.com/2017/09/23/gitlab-ci.html">&lt;p&gt;It wasn’t until recently I realized &lt;a href=&quot;http://gitlab.com&quot;&gt;GitLab&lt;/a&gt;, the opensource alternative to GitHub, has an amazing CI/CD platform.  In my last post on &lt;a href=&quot;./2017-08-11-how-to-choose-a-continuous-integration-tool.html&quot;&gt;How to Choose a Continuous Integration Tool&lt;/a&gt; I outlined my key criteria to choosing a CI tool.  More often than not, CI tools end in developer frustration at the complexity, poor UX, and high amounts of effort to tune it just right.  CI shouldn’t be that complicated.&lt;/p&gt;

&lt;p&gt;On the flip side there are many CI tools out that put a high emphasis on simplicity and well thought out design but they leave the developer just as frustrated with the lack of flexibility (&lt;strong&gt;*ahem*&lt;/strong&gt;.. TravisCI).&lt;/p&gt;

&lt;p&gt;GitLab has won me over.  It offers a well thought out balance of a elegance and power.  Let’s take a close look at how GitLab stacks up to my criteria mentioned last post for evaluating a CI tool.&lt;/p&gt;

&lt;h2 id=&quot;deployment-model-is-it-saas&quot;&gt;Deployment Model: Is it SaaS?&lt;/h2&gt;
&lt;p&gt;Yes! GitLab have a SaaS version of their CI platform that makes simple to get going without any installations, hardware, or the overhead of about upgrades and security patches.  They have a very generous free tier that includes private repos and lots of CI minutes.  The one caveat, and maybe it’s a big caveat, is that you need to also be using GitLab as an origin for your source code.  What makes this bearable is that GitLab as an all-in-one solution is &lt;em&gt;really good&lt;/em&gt;.  I’ll get to that later.&lt;/p&gt;

&lt;p&gt;For the on-prem lovers, it also gives you that option if you need to really scale it or put it behind a firewall. There is even a clever hybrid option to have the CI service as SaaS but communicating with a local dev machine as a CI Runner.  Helpful if you run out of time on the GitLab provided runners I suppose.&lt;/p&gt;

&lt;h2 id=&quot;configuration-is-it-yml&quot;&gt;Configuration: Is it YML?&lt;/h2&gt;
&lt;p&gt;Yes! GitLab has an extremely easy to use declarative YML configuration.  It’s in source control, no complicated UIs to navigate and lots of flexibility. Here is the YML for the Weather Hunt backend:&lt;/p&gt;

&lt;div class=&quot;language-yml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;piohhmy/weatherhunt-primary:0.0.1&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;before_script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;pip install -r requirements-dev.txt&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;stages&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;deploy&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;unit_tests&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nosetests&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;deploy_staging&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;deploy&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;npm install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;npm run deploy-test&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;deploy_production&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;stage&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;deploy&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;npm install&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;npm run deploy-prod&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;only&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;master&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Personally, I find it very intuitive to have the CI/CD rules based on branch.  Check something into a feature branch and it gets deployed to a staging environment for exploratory testing.   Check it into master and it’s deploy to production after the checks pass.  If you prefer deploy on tag, it supports that too.&lt;/p&gt;

&lt;h2 id=&quot;ci-runners-is-it-docker&quot;&gt;CI Runners: Is it Docker?&lt;/h2&gt;

&lt;p&gt;Yes! Note in the above CI configuration I’m using a custom Docker image for the CI runner.  For this application I need both Python and Node to test and deploy the app.  Rather than install Python and Node everytime the CI runs, a simple Dockerfile can be written and uploaded to Dockerhub.  Here’s the Dockerfile used for the referenced &lt;code class=&quot;highlighter-rouge&quot;&gt;image: piohhmy/weatherhunt-primary&lt;/code&gt; in the above config.&lt;/p&gt;

&lt;div class=&quot;language-docker highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; python:2.7&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;RUN &lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-sL&lt;/span&gt; https://deb.nodesource.com/setup_6.x | bash -
&lt;span class=&quot;k&quot;&gt;RUN &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt; nodejs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This Dockerfile creates a simple Node + Python prebaked image that is ready to rock everytime the CI runs.  This keeps the CI feedback cycles quick and the CI configuration simple.&lt;/p&gt;

&lt;h2 id=&quot;pipelines-is-it-flexible&quot;&gt;Pipelines: Is it Flexible?&lt;/h2&gt;
&lt;p&gt;Yes! The pipelines support a multitude of different continuous delivery, branching, and tagging models.  The core concept is there are “stages” which are composed of “jobs”.  All the jobs in a stage will run in parallel.  If all the jobs in a stage complete, then the next stage executes. This provides a simple yet flexible model for mapping out the pipeline.&lt;/p&gt;

&lt;p&gt;The icing on the cake with the pipelines is that it has a great visualization of the CI progress once it’s running.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/gitlab-pipelines.png&quot; alt=&quot;GitLab Pipeline&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-gotcha-its-all-or-nothing&quot;&gt;The Gotcha. It’s all or nothing&lt;/h2&gt;

&lt;p&gt;Admittedly, I was at first skeptical thinking GitLab was the Github knockoff for those wanting to tinker and be pained by a half baked open source project.  I was wrong.  GitLab is a fantastic central platform to manage source code.  Code viewing, issue management, and pull requests (they call them merge requests.. which actually makes a bit more sense) are all there.  They have markdown support everywhere, ability to host static pages (ala this blog), emoji reactions (crucial), and unlimited private repos.&lt;/p&gt;

&lt;p&gt;It’s a bit of an ask to migrate everything to GitLab to take advantage of the CI.  Though, the process is surprisingly smooth. GitLab supports Github as an OAuth provider with a simple import process for all your existing projects.&lt;/p&gt;

&lt;p&gt;I’ve been using GitLab now for a few months and have only found a few places where there is slightly less polish than GitHub. They are minor gripes though, like sometimes the pages require a refresh to get updated.  The fantastic built-in CI, the open source model, the generous hosted free tier for hobby projects, and the on-prem option for enterprise work makes it a joy to work with.&lt;/p&gt;

&lt;p&gt;Check out the the &lt;a href=&quot;https://about.gitlab.com/features/gitlab-ci-cd/&quot;&gt;GitLab CI Docs&lt;/a&gt; and compare it to your CI tool of choice.  What impresses you? What’s lacking?&lt;/p&gt;</content><author><name></name></author><category term="agile" /><category term="dev" /><category term="ci" /><summary type="html">It wasn’t until recently I realized GitLab, the opensource alternative to GitHub, has an amazing CI/CD platform. In my last post on How to Choose a Continuous Integration Tool I outlined my key criteria to choosing a CI tool. More often than not, CI tools end in developer frustration at the complexity, poor UX, and high amounts of effort to tune it just right. CI shouldn’t be that complicated.</summary></entry></feed>