ECS, how to add user-data after creating ecs instance

天涯浪子 提交于 2020-12-15 05:58:54

问题


I can't find a way to specify a user-data after creating ECS instance definition.

Document says You can pass this user data into the Amazon EC2 launch wizard in Step 6.g of Launching an Amazon ECS Container Instance.

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html#multi-part_user_data

ECS is launched automatically, how do you specify the user data?

I want to send /var/log/syslog to cloudwatch and I need to add user data (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_cloudwatch_logs.html)


回答1:


I had to add the user data as a autoscaling group property

steps are

  1. copy existing launch configuration
  2. edit user data of the launch configuration
  3. edit autoscaling group to use the created launch configuration
  4. terminate ecs instances so that the modified autoscaling group launches new ec2 with new launch configuration



回答2:


via terraform we can pass it as template file within launch config

data "template_file" "user_data" {
  template = "${file("${path.module}/templates/user_data.sh")}"

  vars = {
    ecs_config        = "${var.ecs_config}"
    ecs_logging       = "${var.ecs_logging}"
    cluster_name      = "${var.cluster}"
    env_name          = "${var.environment}"
    custom_userdata   = "${var.custom_userdata}"
    cloudwatch_prefix = "${var.cloudwatch_prefix}"
  }


来源:https://stackoverflow.com/questions/59126603/ecs-how-to-add-user-data-after-creating-ecs-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!