简体   繁体   English

上传文件到ECS任务

[英]Uploading file to ECS task

I'm trying to upload a simple .yml file when creating an ECS task via Terraform, here is the code ./main.tf :我在通过 Terraform 创建 ECS 任务时尝试上传一个简单的.yml文件,这里是代码./main.tf

resource "aws_ecs_task_definition" "grafana" {
  family                   = "grafana"
  cpu                      = "256"
  memory                   = "512"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  container_definitions = jsonencode([
    {
      name  = "grafana"
      image = "grafana/grafana:latest"
      portMappings = [
        {
          containerPort = 3000,
          hostPort      = 3000,
          protocol      = "tcp"
        }
      ]
    }
  ])
}

How do I go about adding ./datasource.yml (located on my host machine) to the container within the task definition so that when the task runs it can use it? go 如何将./datasource.yml (位于我的主机上)添加到任务定义中的容器,以便在任务运行时可以使用它? I wasn't sure if volume { } could be used?我不确定是否可以使用volume { }

I think you have two alternatives here:我认为您在这里有两种选择:

  • rebuild the docker image including your modified datasource.yaml.重建 docker 图像,包括修改后的数据源。yaml。

COPY datasource.yaml /usr/share/grafana/conf/provisioning/datasource.yaml

or或者

  • mount a volume that you can easily mount and push files programmatically (EFS turns out to be a bit complicated to do this)安装一个卷,您可以轻松地以编程方式安装和推送文件(EFS 这样做有点复杂)
mount_points = [ {
      sourceVolume  = "grafana"
      containerPath = "/var/lib/grafana/conf/provisioning"
      readOnly      = false
    }
  ]
  volumes = [
    {    
     name      = "grafana"
     host_path = "/ecs/grafana-provisioning"}
  ]

I wasn't sure if volume { } could be used?我不确定是否可以使用volume {}?

As a matter of fact you can, check the docs https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#example-usage事实上,您可以查看文档https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#example-usage

volume {
  name      = "grafana-volume"
  host_path = "./datasource.yml"
}

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

相关问题 通过 API 网关上传 zip 文件(代理到 ECS)导致 zip 文件损坏 - Uploading zip file through API Gateway (proxying to ECS) results in corrupted zip file ECS任务卡在PENDING state - ECS task stuck in PENDING state 无法运行 ECS 外部任务 - Cant run ECS external task ECS 中退出的任务中的基本容器 - Essential Container in task exited in ECS ECS 任务未运行 - AWS Cognito - ECS Task Not Running - AWS Cognito 如何在 AWS 中创建变量并在 .env 文件中使用它们进行 ECS 部署任务 - How to create variables in AWS and use them in an .env file for ECS deploy task 从 Fargate ECS 任务访问 EFS 文件系统 - 没有任何类型的错误消息就无法工作 - Accessing EFS file system from Fargate ECS task - Not working without any kind of error message 具有 GitHub 操作的 Amazon ECS 卡在部署 ECS 任务定义上 - Amazon ECS with GitHub Actions Stuck on Deploying ECS Task Definition AWS ECS Exec 对 ECS Fargate 任务的 shell 访问失败(无法启动 shell:无法启动 pty:fork/exec C:/Program:没有这样的文件或目录) - AWS ECS Exec fails on shell access to ECS Fargate task (Unable to start shell: Failed to start pty: fork/exec C:/Program: no such file or directory) ECS FARGATE 任务定义与 docker 中心图像 - ECS FARGATE TASK definition with docker hub image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM