Skip to content

Commit

Permalink
fix: lambda-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalia committed Jan 28, 2024
1 parent 59c030c commit a54b7f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
9 changes: 9 additions & 0 deletions infra/api/make_lamda_layer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
beautifulsoup4==4.9.1
certifi==2022.12.7
chardet==3.0.4
idna==2.10
requests==2.31.0
soupsieve==2.0.1
zulip==0.8.2
sentry-sdk==1.14.0
python-lambda==11.8.0
33 changes: 18 additions & 15 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -160,36 +160,39 @@ resource "aws_lambda_permission" "apigw_lambda" {

# create zip file from requirements.txt. Triggers only when the file is updated
resource "null_resource" "lambda_layer" {
triggers = {
requirements = filesha1(local.requirements_path)
}
# triggers = {
# requirements = filesha1(local.requirements_path)
# }
# the command to install python and dependencies to the machine and zips
provisioner "local-exec" {
command = <<EOT
/bin/bash
python3 -m venv test_lambda_layer #Python is the name of de layer
soure python/bin/active
pip install -r api/requirements.txt -t python/lib/python3.8/site-pakages
#zip -r python.zip test_lambda_layer
pip install virtualenv &&\
virtualenv --python=/usr/bin/python3.8 test_lambda_layer &&\
source python/bin/active
pip install -r api/requirements.txt -t python/lib/python3.8/site-pakages &&\
ls test_lambda_layer &&\
wget https://mongulu-files.s3.eu-central-1.amazonaws.com/7zz && chmod u+x 7zz &&\
./7zz a python.zip test_lambda_layer &&\
./7zz l python.zip
EOT
}
}
# Archive a single file.

data "archive_file" "test_zip" {
type = "zip"
source_dir = "test_lambda_layer"
output_path = "python.zip"
depends_on = [null_resource.lambda_layer]
}
# data "archive_file" "test_zip" {
# type = "zip"
# source_dir = "test_lambda_layer"
# output_path = "python.zip"
# depends_on = [null_resource.lambda_layer]
# }

resource "aws_lambda_layer_version" "test_lambda_layer" {
filename = "python.zip"
layer_name = "test_lambda_layer"
compatible_runtimes = ["python3.8", "python3.7"]
# depends_on = [null_resource.test_lamdazip]
depends_on = [null_resource.lambda_layer]
}

resource "aws_lambda_function" "lambda" {
Expand Down

0 comments on commit a54b7f8

Please sign in to comment.