我使用的是 OSX M1 芯片。我不确定为什么会收到此错误,因为我认为我已经使用 linux/amd64 基础映像正确构建了映像。我有以下文件:
Dockerfile:
FROM --platform=linux/amd64 python:3.12
COPY main.py ${LAMBDA_TASK_ROOT}
CMD ["main.handler"]
在与我的 Dockerfile 相同的目录中,我有一个
main.py
:
def handler(event, context):
print(event)
return event
我有以下 lambda.tf 文件:
module "my_test_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "4.17.0"
function_name = local.deployment_prefix
handler = "main.handler"
timeout = 900
memory_size = 1536
# use_existing_cloudwatch_log_group = true
create_package = false
package_type = "Image"
architectures = ["x86_64"]
image_uri = "1234567890.dkr.ecr.eu-west-2.amazonaws.com/my-test-repo:latest"
role_permissions_boundary = var.role_permissions_boundary_arn
attach_policies = true
number_of_policies = 1
policies = [
aws_iam_policy.my-test-lambda.arn
]
tags = {
Component = local.module_name
}
}
我在登录 ECR 后运行以下命令
docker build -t my-test-image .
docker tag my-test-image 1234567890.dkr.ecr.eu-west-2.amazonaws.com/my-test-repo:latest
docker push 1234567890.dkr.ecr.eu-west-2.amazonaws.com/sam-test-repo:latest
然后,当我通过控制台运行 lambda 时,出现以下错误:
状态:错误错误类型:Runtime.InvalidEntrypoint 错误:fork/exec /lambda-entrypoint.sh:exec 格式错误 运行时.InvalidEntrypoint
我不太确定我在这里做错了什么。我遵循了其他问题中的其他答案,但不断收到此错误。
创建 Lambda 函数时,
handler
由两部分组成:
lambda_function.lambda_handler
。在您的情况下,Lambda 函数名称是使用 local.deployment_prefix
值定义的,这意味着必须使用函数名称而不是 main
。代码中处理函数的名称是 handler
(用 def handler
定义)。换句话说,terraform中需要改变的是以下内容:
module "my_test_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "4.17.0"
function_name = local.deployment_prefix
handler = "${local.deployment_prefix}.handler"
timeout = 900
memory_size = 1536
# use_existing_cloudwatch_log_group = true
create_package = false
package_type = "Image"
architectures = ["x86_64"]
image_uri = "1234567890.dkr.ecr.eu-west-2.amazonaws.com/my-test-repo:latest"
role_permissions_boundary = var.role_permissions_boundary_arn
attach_policies = true
number_of_policies = 1
policies = [
aws_iam_policy.my-test-lambda.arn
]
tags = {
Component = local.module_name
}
}