问题
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
- copy existing launch configuration
- edit user data of the launch configuration
- edit autoscaling group to use the created launch configuration
- 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