使用 boto3 将目标组添加到 ECS Fargate 任务
Add target group to ECS Fargate task using boto3
我有一个从 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, as well as the AWS documentation,但没有用。我还注意到,即使在网络界面中,也无法执行此操作。
提前致谢。
run_task
用于 运行 完成和退出。对于应该保持 运行 并在负载均衡器后面提供类似于 Web 应用程序的 ECS 任务,您需要使用 create_service
并传递适当的 loadBalancers
设置。
我有一个从 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, as well as the AWS documentation,但没有用。我还注意到,即使在网络界面中,也无法执行此操作。
提前致谢。
run_task
用于 运行 完成和退出。对于应该保持 运行 并在负载均衡器后面提供类似于 Web 应用程序的 ECS 任务,您需要使用 create_service
并传递适当的 loadBalancers
设置。