code-dumps/lambda/dns-query
2024-10-29 13:49:42 +08:00
..
lambda_function.py HistoryPurge: Clearing 219 old commits 2024-10-24 23:09:21 +08:00
README.md DOC: updated doc about creating lambda layer 2024-10-29 13:49:42 +08:00

Steps to create a lambda python package

Create layer

cd layers pip install dnspython -t python/lib/python3.12/site-packages/

Then in terraform, create an archive for the layer

data "archive_file" "dnspython" {
  source_dir  = "layers"
  type        = "zip"
  output_path = "layer-dnspython.zip"
}

resource "aws_lambda_layer_version" "dnspython" {
  description = "Python3 DnsPython library"
  depends_on  = [data.archive_file.layer1]
  filename    = "layer-dnspython.zip"
  layer_name  = "Python3DnsLibrary"
  license_info             = "ISCL"
  compatible_architectures = ["arm64", "x86_64"]
  compatible_runtimes = ["python3.12"]
}

# In the lambda function, reference the layer
resource "aws_lambda_function" "myFunction" {
  ...
  layers           = [aws_lambda_layer_version.libraries.arn]
}