2013-06-19 33 views
0

如何將連接對象連接到區域?我可以創建一個連接。我可以連接到一個地區。如何連接對象鏈接到一個區域Python和boto自動縮放 - 如何連接到區域

region = 'ap-southeast-2' 
conn = AutoScaleConnection(aws_access_key_id, aws_secret_access_key) 
autoscale = boto.ec2.autoscale.connect_to_region(region) 

回答

3

connect_to_region出現在每一博託模塊中,並創建一個連接服務的最佳途徑的方法。在這種情況下,該方法返回一個AutoScaleConnection對象,因此不需要嘗試直接創建連接對象。所以,像這樣將工作:

import boto.ec2.autoscale 
region = 'ap-southeast-2' 
conn = boto.ec2.autoscale.connect_to_region(region, aws_access_key_id="<access_key", aws_secret_access_key="<secret_key>") 
mygroups = conn.get_all_groups() 
... 
+0

我在哪裏把aws_access_key_id,aws_secret_access_key? – Tampa

+0

我編輯了要顯示的代碼示例。基本上,在區域參數之後,可以包含爲類構造函數定義的任何參數。 – garnaat

+0

TypeError:connect_to_region()只需要1個參數(給出3個參數) – Sirex

0

我不能讓garnaat的解決方案,爲我工作,但這個工作:

regionObj = [region for region in boto.ec2.autoscale.regions() if region.name == 'ap-southeast-2'][0] 
as_conn = AutoScaleConnection(api_key, api_secret_key, region=regionObj) 
mygroups = as_conn.get_all_groups()