2015-10-20 30 views
3

我正在調用ecs.create_service這樣的:使用boto3 ECS獲取「創建服務不是冪等的」。爲什麼?

createServiceResponse = ecs.create_service(
clientToken='abc123', 
cluster=options.cluster, 
serviceName=options.service, 
desiredCount=1, 
taskDefinition='relay:' + str(revision), 
role='ecsServiceRole', 
loadBalancers=[ 
    { 
     'loadBalancerName': options.elb, 
     'containerName': 'relay', 
     'containerPort': 8080 
    } 
] 
) 

注意,在clientToken值abc123的時刻,但我已經嘗試了各種不同的字符串。這份文件說,我需要提供,以確保冪等(http://boto3.readthedocs.org/en/latest/reference/services/ecs.html),但是我不斷收到此錯誤:

Traceback (most recent call last): 
    File "./deploy.py", line 103, in <module> 
    'containerPort': 8080 
    File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 301, in _api_call 
    return self._make_api_call(operation_name, kwargs) 
    File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 386, in _make_api_call 
    raise ClientError(parsed_response, operation_name) 
botocore.exceptions.ClientError: An error occurred  (InvalidParameterException) when calling the CreateService operation: Creation of service was not idempotent. 

爲什麼?

回答

7

我想通了。

這是因爲我在現有服務上調用create_service。我應該撥打update_service如下:

ecs.update_service(

cluster=options.cluster, 
service=options.service, 
taskDefinition='relay:' + str(revision),  
desiredCount=1) 
相關問題