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.
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.
Reference bash script and use its outputs in lambda resources.