Using Google Closure Compiled Code for AWS Lambda Functions

clojurescript, javascript

Recently, I tried to get a development environment set up for developing a single page web application ClojureScript - but with a backend written to run on AWS Lambda functions, also in ClojureScript.

ClojureScript seems to use the Google Closure Compiler for compiling JavaScript. The Google Closure Compiler uses its own module and import/export/require system that is different from Node’s module system.

Because AWS Lambda expects your JS to export the handler functions for the Lambda function using the Node module system, I ended up with a real problem:

How do you require Google Closure-compiled ClojureScript into a node module?

The answer ended up being quite simple. Given that Closure is creating a compiled file with name functions.js, which in turn is exporting a namespace functions.core, you can create a new main.js file in the same directory as the compiled functions.js file with the following content:

1
2
var f = require("./functions.js");
module.exports = f.functions.core;

This took me longer than I care to admit to figure out, though that’s probably mostly a function of how little I deal with JavaScript module systems. Since thanks go to Matthew Stump’s post Writing NodeJS Modules in ClojureScript, which had the trick as part of it.

Clojure and ClojureScript Boot and Boot-reload Error

boot, clojure, clojurescript

Recently, I attempted to get started with the boot build system by running the boot-cljs-example repository.

On my system, while running the suggested build script:

1
boot serve -d target/ watch speak reload cljs-repl cljs -sO none

I ran into the following error:

1
2
3
4
5
6
7
8
james@james-desktop: boot serve -d target/ watch speak reload cljs-repl cljs -sO none
WARNING: test already refers to: #'clojure.core/test in namespace: boot.user, being replaced by: #'boot.user/test
             clojure.lang.ExceptionInfo: java.lang.NoClassDefFoundError: clojure/lang/IFn, compiling:(org/httpkit/server.clj:23:11)
    data: {:file "/tmp/boot.user6465695604758877332.clj", :line 21}
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: clojure/lang/IFn, compiling:(org/httpkit/server.clj:23:11)
clojure.lang.Compiler$CompilerException: java.lang.NoClassDefFoundError: clojure/lang/IFn, compiling:(org/httpkit/server.clj:23:11)
         java.lang.NoClassDefFoundError: clojure/lang/IFn
       java.lang.ClassNotFoundException: clojure.lang.IFn

To fix this: note that boot relies on a boot.properties file for version information and uses that instead of your system versions if set.

To fix the error above, change your BOOT_VERSION in boot.properties to be 2.7.2 instead of 2.5.5.

Happy coding! For extra information, see the version information below:

Version & System Notes

To do so, I installed the default version of boot as of the time of writing. The version output of this version is:

1
2
3
4
5
6
james@james-desktop:$ boot --version
#http://boot-clj.com
#Fri Dec 01 03:51:00 EST 2017
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.7.2

Additionally, I am running Java 1.8. and node 7.10 via Ubuntu 16.04’s node package, but with nvm (node version manager) installed.

Docker Permission Denied on Ubuntu 16.04

docker, ubuntu

Recently, I have been messing around with writing and deploying AWS Lambda Functions and Microsoft Azure Functions - two “serverless” technologies that have a lot of promise for certain applications.

For development environments, both rely on using docker images provided by the respective vendors to run your functions locally.

I attempted to set up Docker on Ubuntu 16.04 by running sudo apt install docker, which appeared to succeed.

However, when attempting to run docker run hello-world - a command which should pull a ‘hello world’ image from one of the public docker repositories, then run it - I received an error to the effect of:

1
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

The solution to this problem is to either (a) run your docker commands as root, or (b) add your login user to the docker group.

Option (a) is not preferred, as introducing a sudo dependency will quickly lead you to ‘sudo hell’ where everything of use requires sudo.

For option (b), you can run sudo usermod -a -G docker $USER, which will add your user to the docker group.

For the change to take effect, you will need to fully log out of your account and log back in.

Things I Am Reading

reading, thinking,

Over the past week or so, I have been spending a lot more time reading blogs.

Upon reflection, I am trying to fill a specific hole in my life: I’m not having enough interesting discussions with smart people who have interesting things to say about things that I don’t know about.

That sentence seems a bit long, and maybe convoluted, but I think it is about right. The absence of it is grinding on me.

Prior to 2006, I think this mostly came from speaking to my parents. Being under 12, this was acceptable.

From 2006 to 2009, this mostly came from spending an inordinate amount of time on a old-school web forum that, while centered around a particular game, had a politically diverse, tight knit community who liked to talk about all sorts of things.

From 2009 to 2011, I had truly fantastic teachers and classmates as conversation partners at Robinson High School in Tampa, Florida. In particular, three of my History teachers spent hundreds of hours in ‘study hall’ discussing all manner of things, ultimately teaching me much more than the State of Florida would’ve liked.

From 2011 to 2014, interesting discussions came from a combination of college classes (interesting, but outside of the mathematical classes, lacking), the University Economics Society at the University of Florida (light on economics, heavy on interesting discussion), and thousands of hours of discussion with Steve Spalding (@sbspalding) and Miguel Barbossa (@MiguelABarbossa, check out citizenaudit.org).

I graduated, I threw myself into my company, and then another. For a period in 2016, I got my fill from a wonderful private Facebook group. But like most communities, its moment ended; while it tided me over, after the 2016 election, the high quality discussion ended1.

Then, for three months in 2017, I had a taste of this again, hanging out with the wonderful Richard Stein in Hong Kong.

Given that for the majority of my life I’ve gotten most of my interesting discussion online, it shouldn’t be hard to reconstruct this.

But since 2014, the world has moved. Going through my old follow lists, many people are no longer active. Those who are active are posting less interesting (alternatively: less controversial) ideas in public spaces2.

I am resolved to rebuild. I’ve started by rejecting algorithmic aggregation3: I want to find content that makes me a better thinker and person, not content that monetizes well. The ‘indie web’ (we used to call it ‘the web’).

Here are the blogs that I find interesting and you should check out, along with a couple of keywords:

Dan Luu’s Blog: Low level programming, computer engineering, excellent essays about the market for technical talent.

DaedTech: Mostly commentary on navigating freelance technology roles; excellent writing.

Ben Kuhn: I’ve not read the archives, but general technology, effective altruism.

Decibels and Decimals, Brady Fowler’s music / data sci blog; not super active but every post is a delight.

Brute Reason, social justice, social issues.

Ribbonfarm, tech, culture, deep thinking

Evan Miller, statistics, programming. I love his post on dealing with floating point exponentiation when plotting the F distribution

If you have any recommendations, I’d love to hear them. Please reach out.

I’m also looking to correspond with people who want to discuss whatever is interesting to them at the moment. Please reach out.


  1. My assessment is the very real consequences of the 2016 election made discussing politics just a little too serious.

  2. I’m not sure if this is sampling bias, or just natural attrition. The number of blogs I used to follow that no longer provide RSS, or switched to Medium, then died, is too high, though.

  3. For now, feedly is working well - it appears to have a quasi-magical ability to subscribe to some sites that don’t have an RSS feed

The Internet Enclosure

Stub of an idea: we can compare the movement of the internet from the web to enclosed platforms like Facebook, Twitter, etc, to the enclosure of English landholdings.