【问题标题】:Add target group to ECS Fargate task using boto3使用 boto3 将目标组添加到 ECS Fargate 任务
【发布时间】:2020-02-09 00:29:24
【问题描述】:

我有一个从 lambda 函数调用的 Fargate 任务。我还有一个负载均衡器,它设置为特定的目标组,比如说 tg-x。我使用 boto3 来运行上述任务。但是,我不使用服务,因为我只需要手动运行此任务。无论如何我可以将目标组添加到此任务中,例如在服务中?

我的代码:

def lambda_handler(event,context):
    client = boto3.client('ecs')
    response = client.run_task(
        cluster='oops-dev', # name of the cluster
        launchType = 'FARGATE',
        taskDefinition='oops-dev-oops-oops:oops'
        count = 1,
        platformVersion='LATEST',
        networkConfiguration={
            'awsvpcConfiguration': {
                'subnets': [
                    'subnet-oops',
                    'subnet-oops',
                    'subnet-oops'
                ],
                'securityGroups': [
                    'sg-oops'
                ],
                'assignPublicIp': 'ENABLED'
            }
    })

    return str(response)

我检查了boto3 docs,以及AWS documentation,但无济于事。我还注意到,即使在 Web 界面中,也无法做到这一点。

提前致谢。

【问题讨论】:

    标签: amazon-web-services aws-lambda boto3 aws-fargate


    【解决方案1】:

    run_task 用于运行完成并退出的东西。对于应该保持运行并为负载均衡器后面的 Web 应用程序提供服务的 ECS 任务,您需要使用 create_service 并传递适当的 loadBalancers 设置。

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2019-05-15
      • 2021-03-07
      • 1970-01-01
      • 2019-11-26
      相关资源
      最近更新 更多