Using Serverless Framework to build and deploy Docker images for AWS Lambdas

AWS Lambdas can be packaged and deployed using a Docker image, described in the docs here.

Serverless Framework makes building and deploying a Docker based Lambda incredibly simple. If you have a simplest Dockerfile like this (from the docs here):


# Assumes your function is named "app.js", and there is a package.json file in the app directory 
COPY app.js package.json  ${LAMBDA_TASK_ROOT}

# Install NPM dependencies for function
RUN npm install

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ] 

The handler to be packaged in this image is this simplest hello world function:

exports.handler =  async function(event, context) {
    console.log("EVENT: \n" + JSON.stringify(event, null, 2))
    return "hello!"

To define a Lambda using this image, with Serverless define an ECR section like this to define your image, which will get built using the above Dockerfile in the same folder:

service: lambda-container-1

  name: aws
        path: ./

      name: lambda-container-example

Run ‘serverless deploy’ and it builds the image, uploads to ECR, and deploys the Lambda all for you.

After deploying, on first test I got this error:

  "errorMessage": "RequestId: 58fe500f-26ee-44ba-b6a9-6079b6ff2896 Error: fork/exec / exec format error",
  "errorType": "Runtime.InvalidEntrypoint"

The key part of this error is this “exec format error”. I’m building and deploying this from my M1 MacBook Pro, which is Apple’s arm64, not x64.

If we look in the AWS Console for this lambda, on the first page under Image you’ll see the Lambda runtime architecture:

Updating the serverless.yml to include ‘architecture: arm64’, redeploy and now the architecture is arm64:

Invoking with ‘serverless invoke –function hello’ and now it successfully runs!

The Inevitable Financial Exploitation of Technology

I started writing this post a number of times over the past few weeks, but the further I got into it I kept finding a nagging concern I couldn’t put my finger on, I kept getting the feeling that there’s something inherently wrong with what I learning.

I’ve spent time reading a large number of articles and posts on NFTs, and scrolled through many heated discussion threads where both sides argued their points of view. The one common thing that those supporting the concept were alarmingly (and even disturbingly) passionate, but in most cases they weren’t able to convincingly sell their point of view leading to frustration and comments like “You just don’t understand it!”. The weird thing is despite their passion and enthusiasm it was pretty clear that they didn’t understand what they were trying to promote either.

It is true that the original idea behind NFTs was to enable a digital marketplace for artists to sell digital works online in a way where artists could prove provenance and track ownership. You can read about the origin’s as summarized by Anil Dash in this Atlantic article. Kevin McCoy and Dash looked to take advantage of blockchain technology to solve this problem, but where blockchain provides a provable ledger of transactions it fails to address other concerns:

  • it doesn’t prevent works of art from being duplicated
  • it doesn’t prove one copy of a digital asset is the original version verses a copy
  • it doesn’t provide a mechanism to sell the art itself (other than a token that represents the art)

The last point is interesting and maybe not obvious to a casual observer. When you buy an NFT for a work of art online (or anything for that matter), but you’re buying is a token in a blockchain that represents that artwork. You’re not buying the art itself and it’s not even digitally contained within the token. Due to limitations on how much data can we inserted into an entry in the blockchain, the art work needs to be stored ‘somewhere else’. That somewhere else can be another website. There may be a link within the token that points to the url location of that website, but immediately you start to see the issues and limitations with this approach. Websites don’t last forever. They can go down, whoever is running and paying for them can go out of business or just decide to close down the site. The location of your artwork you have ‘bought’ is therefore not even permanent, you can lose access to your artwork at any point. The only thing you’re left with is the token itself.

“Oh, but I can download a copy of the art and keep it myself” – and here’s the other two points. So can anyone else. Seeing the drama online where people are suddenly realizing anyone can ‘right-click save’ their work has been amusing. This problem has always existed online, and NFTs do nothing to prevent this. NFTs are at best only a partial solution to enabling online art sales, but the gaps they don’t address are significant enough that it doesn’t make a very compelling or useful solution.

So why the sudden gold rush? Why are people paying thousands for images of monkeys and pixel art punks? The remainder or Dash’s article on The Atlantic talks about how the wealthy look for places to ‘park’ their assets, and the onrush of grifters and con artists. Where there’s money to be made by taking advantage of others you’ll never find a shortage of people looking for opportunities to get people to part with their money. It’s no longer about artists selling their work, it’s digital baseball cards and speculation on selling your cards to others for a profit. The trouble when there’s a limited number of players in the game is at some point it’s the same people buying and selling to each other. In order to make a profit you need to find someone who’s willing to pay more than what you initially paid. Encouraging others to get in the game seems to be a big part of this whole scam. If you can find someone new to sell to at a profit you come out ahead of the game and you’ve passed the risk onto someone else.

At the start, this whole thing started with good intentions. It was about finding a technology solution to help artists sell their work. At this point it’s clearly far beyond this. No-one in their right mind is going to pay thousands for a poorly drawn monkey shooting lasers from it’s eyes. Sure, there are real artists selling real art work, but they’re lost in the rush of people looking to make money from the stupidity of others.

And then there’s the issue of the environmental impact of NFTs and blockchains. There’s an exceptionally well written article about this and I encourage everyone to read this article:

Here is the article you can send to people when they say ‘but the environmental issues with cryptoart will be solved soon, right?’

Like most things it started with good intentions, it was about the art, but now it’s all about ripping off as many other people as you can and getting out before you’re the last one holding the bag.