Be careful of whitespace in .php files

So I was debugging some anomalous behavior on my website and as I was poking around, I half-consciously noticed the change bars in in my editor that showed two extra newlines at the end of a .php file. But I dismissed this even as soon as I saw it because… I mean, it’s just whitespace. At the end of a file.

Read More

Featured Video Play Icon

Jessitron & Avdi Attempt Event Storming

Recently Jess & I decided we needed an app idea to give us an excuse to write code, and last night we spent 45 minutes sketching it out with post-its on a wall. This was our first highly uneducated stab at event-storming, but it was fun and helped us think through what are the tangible, actionable outputs we want to see from our app.

Read More

SIGAVDI #83: Cream Cheese BBQ Chicken Edition

Hello friends,

Before I get into this week fortnight’s newsletter, a quick note: I have immediate availability to take on a new consulting client! I’m particularly good with gnarly gnarly Ruby/Rails codebases, as well as coaching/mentoring junior and midlevel engineers, helping to evolve technical architecture, and facilitating the spread of healthy practices within your organization. More info here!

Read More

A hand-cranked pump in a rice field

The Well in the Field

When I was a child, I lived with my parents in the woods. We had an old-fashioned hand-dug well, the kind from storybooks that looks like a big hole in the ground lined with stacked stones. In summer, if there was a drought, the well would sometimes run dry.

Read More

Hiking near the Meramec River

SIGAVDI #82: Broccoli Rabe Edition

Hello friends,

It’s been another couple weeks of hunkering down with Jess & family in St. Louis. It turns out the way I deal with social distancing is to buckle down and work really hard. When all this is over I may need to impose periodic “productivity quarantines” on myself to match this level of output.

Read More

Reproducibly Setting Production Environment Variables for AWS Lambda Apps

The problem with infinitely flexible building blocks is that there are always a half-dozen well-documented ways to do things wrong.

I wanted my AWS Lambda app (I refuse to call it a “function” because it isn’t) to get the third-party API keys it needs from environment variables. Not from hardcoded strings or config files.

The most immediately accessible way to set up env vars for a Lambda is via the AWS console. But that’s not a reproducible, versionable workflow I can capture in my project.

Searching for info on setting up environment variables in a SAM-based AWS Lambda app turns up a lot of results. It seems you can set variables in the SAM config in template.yaml.

  Type: AWS::Serverless::Function
    CodeUri: hello_world/
    Handler: app.lambda_handler
    Runtime: python3.7
        API_KEY: 12345...

More usefully, you can define env vars that apply to all of your functions by putting them in the globals section that normally lives at the top of template.yaml

# ...
      API_KEY: 12345...

Which is all great, except that I explicitly don’t want these variable values to apply universally, and I don’t want them to be checked-in to my repo. I just want to set them for my production deployment.

My searching next took me down the rabbit hole of AWS Systems Manager Parameter Store. But that’s way too heavyweight a solution for what I want to do.

Finally, I realized that I could probably set env vars via the aws CLI (not sam). Like everything to do with AWS, the command isn’t particularly intuitive, but here’s what I cam up with:

aws --region us-east-1 lambda  update-function-configuration \
   --function-name myapp-MyFunction-1234ABCD \
   --environment "Variables={API_KEY=12345}"

Some points to note:

  1. Nothing worked until I explicitly set the –region
  2. Environment variables are part of a “function configuration”
  3. The function name for a SAM-managed app is the full name that SAM invents, including the app name, the function name, and some ID garbage at the end.
  4. You can’t just set environment variables directly; that would be too easy. You need to pass Variables={...}, where the contents of the curly braces are key=value pairs delimited by commas.

This gives me a documentable, reproducible template for setting API key environment variables in just the production deployment. Which is what I wanted.

Oh no, Sam the Firefly was in a jar!

AWS SAM in a Docker Dev Container

When you look up AWS Lambda tutorials they usually walk you through using the web console to roll out a function-as-a-service. This is a nice parlor trick, but it doesn’t help you do real work on Lambda because it’s not reproducible. Until Github Actions can include “click 150 different things on”, reproducible builds means writing code on a developer machine, and making use of code-as-config and command-line tools to build and deploy.

So yesterday I took another crack at learning AWS SAM (Serverless Application Model), which is a command-line-and-config-files abstraction layer on top of AWS CloudFormation.

Read More