繁体   English   中英

Terraform:是否可以根据 lambda 定义一个空图像?

[英]Terraform: Is it possible to define an empty image based lambda?

当定义package_type = Zip的 lambda 时,可以创建一个虚拟的temp.zip文件并将其设置为 lambda 的文件名。

创建时,lambda 基本上将有一个空的 zip,稍后可以将其替换为向其推送工件的持续交付管道之类的东西。

我注意到在工作中使用了这种模式。

但是,我正在使用 lambda 容器图像来处理一些个人问题。

我将其设置为package_type = Image ,并设置其他required的 arguments(根据 Terraform 文档)。 但是当我运行terraform apply时,我收到一条错误消息,指出必须设置 lambda 的image_uri参数。

如果我还没有构建图像怎么办? 是否有一些等效的技术来满足image_uri要求,基本上创建一个“空”lambda,我稍后计划通过 CD 管道更新它?

一直在四处寻找,但尚未找到解决方案。

如果我还没有构建图像怎么办?

然后你不能创建容器 lambda。 您必须提供一些图像 url。 它可以是什么都不做的虚拟图像,但它必须先存在才能创建这样的 lambda function。

然后稍后您可以使用其他内容更新虚拟图像。

是的你可以! 这个问题已经在这里回答了,我已经在下面复制了

data "aws_ecr_authorization_token" "token" {}

resource "aws_ecr_repository" "repository" {
  name                 = "lambda-${local.name}-${local.environment}"
  image_tag_mutability = "MUTABLE"
  tags = local.common_tags
  image_scanning_configuration {
    scan_on_push = true
  }
  lifecycle {
    ignore_changes = all
  }

  provisioner "local-exec" {
    # This is a 1-time execution to put a dummy image into the ECR repo, so 
    #    terraform provisioning works on the lambda function. Otherwise there is
    #    a chicken-egg scenario where the lambda can't be provisioned because no
    #    image exists in the ECR
    command     = <<EOF
      docker login ${data.aws_ecr_authorization_token.token.proxy_endpoint} -u AWS -p ${data.aws_ecr_authorization_token.token.password}
      docker pull alpine
      docker tag alpine ${aws_ecr_repository.repository.repository_url}:SOME_TAG
      docker push ${aws_ecr_repository.repository.repository_url}:SOME_TAG
      EOF
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM