Terraform部署AWS Lambda(ECR镜像)时ImageConfig参数报错解析
问题:Terraform部署AWS Lambda函数时ImageConfig参数不支持错误
部署时遇到以下错误:
Error: error creating Lambda Function (1): InvalidParameterValueException: The ImageConfig parameter is not supported for functions created with deployment packages. │ { │ RespMetadata: { │ StatusCode: 400, │ RequestID: "b8cda8ac-981f-417d-8f98-b8065cd5e167" │ }, │ Message_: "The ImageConfig parameter is not supported for functions created with deployment packages.", │ Type: "User" │ } │ │ with module.lambda["oon-holiday"].aws_lambda_function.service_lambda[0], │ on ../../modules/lambda/main.tf line 115, in resource "aws_lambda_function" "service_lambda": │ 115: resource "aws_lambda_function" "service_lambda" { │ ╵
查看Terraform计划输出,配置存在矛盾:
+ resource "aws_lambda_function" "service_lambda" { + architectures = (known after apply) + arn = (known after apply) + description = "oon-holiday" + function_name = "development-use1-inventory-oon-holiday" + handler = "index.main" + id = (known after apply) + image_uri = "794528122463.dkr.ecr.us-east-1.amazonaws.com/inventory-service:latest" + invoke_arn = (known after apply) + last_modified = (known after apply) + memory_size = 1024 + package_type = "Zip" + publish = false + qualified_arn = (known after apply) + qualified_invoke_arn = (known after apply) + reserved_concurrent_executions = 0 + role = "arn:aws:iam::794528122463:role/development-use1-inventory-lambda-oon-holiday" + runtime = "python3.9" + signing_job_arn = (known after apply) + signing_profile_version_arn = (known after apply) + source_code_hash = (known after apply) + source_code_size = (known after apply) + tags = { + "Environment" = "development" + "Lifetime" = "permanent" + "Purpose" = "use1" + "Squad" = "Platform" + "ZipBucket" = "cp-lambda-code" + "ZipKey" = "default/init.zip" } + tags_all = { + "Environment" = "development" + "Lifetime" = "permanent" + "Purpose" = "use1" + "Squad" = "Platform" + "ZipBucket" = "cp-lambda-code" + "ZipKey" = "default/init.zip" + "t_billing_center" = "Production-Technology" + "t_contact" = "squad-platform@" + "t_platform" = "classpass" + "t_project" = "Platform" + "t_purpose" = "use1" + "t_system_owner" = "platform" + "t_team" = "cp-platform" } + timeout = 30 + version = (known after apply) + environment { + variables = { + "terraform" = "true" } } + image_config { + command = [ + "start-lambda", + "com.classpass.inventory.lambda.OutOfNetworkHolidayHandlerKt", ] + entry_point = [] } + vpc_config { + security_group_ids = [ + "sg-cfd308b4", ] + subnet_ids = [ + "subnet-0d0e756323d870e41", + "subnet-0fa79744", ] + vpc_id = (known after apply) } }
用户疑惑:明明使用了ECR镜像,却提示ImageConfig不支持,该参数应该是容器镜像场景下的实用配置。
解决方案
问题核心是配置混用了Zip部署包和容器镜像两种Lambda部署模式:
- 当前
package_type设为"Zip",属于部署包模式,该模式下Lambda不支持image_config参数 - 但同时配置了
image_uri(容器镜像地址)和image_config,这是容器镜像模式的专属配置
修复步骤:
- 将
package_type修改为"Image",明确使用容器镜像部署模式:package_type = "Image" - 移除Zip模式专属参数:
handler、runtime,这两个参数仅适用于Zip包部署的Lambda,容器镜像模式不需要 - 确认
image_uri指向的ECR镜像有效,image_config配置符合业务需求(若镜像内部已内置启动命令,也可选择移除image_config块)
调整后的核心配置示例:
resource "aws_lambda_function" "service_lambda" { function_name = "development-use1-inventory-oon-holiday" description = "oon-holiday" role = "arn:aws:iam::794528122463:role/development-use1-inventory-lambda-oon-holiday" package_type = "Image" image_uri = "794528122463.dkr.ecr.us-east-1.amazonaws.com/inventory-service:latest" memory_size = 1024 timeout = 30 environment { variables = { "terraform" = "true" } } image_config { command = [ "start-lambda", "com.classpass.inventory.lambda.OutOfNetworkHolidayHandlerKt", ] } vpc_config { security_group_ids = ["sg-cfd308b4"] subnet_ids = ["subnet-0d0e756323d870e41", "subnet-0fa79744"] } # 保留其他必要配置... }
内容的提问来源于stack exchange,提问作者Yamikuronue
相关产品推荐
相关产品推荐

