Filebase64sha256 and Terraform

To deploy lambda function or layer you need to provide the zipped code and its source hash, calculated by the filebase64sha256 function. It might cross your memory limits. Here I show you how to avoid it.

The Problem

Calculating hash value is CPU expensive problem and memory should not impact it at all. Unfortunately Terraform loads entire file to memory to calculate hash of it which may cause killing the process.

Calculate in BASH

Utilize bash and OpenSSL to calculate it and return as JSON.

External resource

Reference bash script and use its outputs in lambda resources.