Module creates unusable python pg8000
t-cliff opened this issue · 2 comments
Description
Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the examples/*
directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply
without any further changes.
If your request is for a new feature, please use the Feature request
template.
- ✋ I have searched the open/closed issues and my issue is not listed.
⚠️ Note
Before you submit an issue, please perform the following first:
- Remove the local
.terraform
directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/
- Re-initialize the project root to pull down modules:
terraform init
- Re-attempt your terraform plan or apply and check if the issue still persists
Versions
- Module version [Required]:
5.0.0 - Terraform version:
1.5.0
- Provider version(s):
Reproduction Code [Required]
Steps to reproduce the behavior:
Terraform Code
module "pg8000_lambda_layer" {
source = "terraform-aws-modules/lambda/aws"
version = ">=4.10.2"
create_layer = true
layer_name = "trav-pg8000"
description = "Layer for proxy"
runtime = "python3"
compatible_runtimes = ["python3.8", "python3.9","python3.10"]
source_path = {path = "./Modules/python.zip"}
}
resource "aws_lambda_function" "lambda" {
function_name = "hello_lambda"
layers = [
module.pg8000_lambda_layer.lambda_layer_arn,
]
filename = "${data.archive_file.zip.output_path}"
source_code_hash = "${data.archive_file.zip.output_base64sha256}"
role = "${aws_iam_role.iam_for_lambda.arn}"
handler = "hello_lambda.lambda_handler"
runtime = "python3.9"
environment {
variables = {
greeting = "Hello"
}
}
}
Lambda Code
import os
import pg8000
def lambda_handler(event, context):
return "{} from Lambda!".format(os.environ['greeting'])
Expected behavior
Lambda ran successfully!
Actual behavior
{
"errorMessage": "Unable to import module 'hello_lambda': No module named 'pg8000'",
"errorType": "Runtime.ImportModuleError",
"requestId": "150d96c8-63e3-480c-970f-b7b5554d021e",
"stackTrace": []
}
When I manually and use resource to create the layer the import of pg8000 works as expected, only doesnt work when I use module.
Terminal Output Screenshot(s)
Additional context
module "pg8000_lambda_layer" {
# omitted...
source_path = {path = "./Modules/python.zip"}
}
source_path
is in the incorrect format.
Please look into examples/complete
for more examples -
https://github.com/terraform-aws-modules/terraform-aws-lambda/blob/master/examples/complete/main.tf
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.