需要按小时启动工作区,但 start_workspaces() 和 describe_workspaces() 限制为 25
Need to boot hourly workspaces but start_workspaces() and describe_workspaces() limited to 25
我有以下用于启动工作区的脚本,但它获得了前 25 个工作区,尽管处于 AVAILABLE 或 STOPPED 状态。
我的环境中有 运行 超过 25 个工作区,我想弄清楚我需要添加什么,以便检查我环境中的所有工作区 (50<) 和对处于 STOPPED 状态的那些启动 START。
期待听到您的反馈。
谢谢
import boto3
workspaces = boto3.client('workspaces')
def lambda_handler(event, context):
workspaces_client_list = workspaces.describe_workspaces()
for workspaces_info in workspaces_client_list['Workspaces']:
workspace_id = workspaces_info['WorkspaceId']
workspace_state = workspaces_info['State']
if workspace_state == 'STOPPED':
start_workspaces(workspace_id)
def start_workspaces(workspace_id):
workspaces.start_workspaces(
StartWorkspaceRequests = [
{
'WorkspaceId': workspace_id
},
]
)
The documentation states 你可以在请求参数中提供一个Limit
Limit
The maximum number of items to return.
Type: Integer
Valid Range: Minimum value of 1. Maximum value of 25.
Required: No
您只能获得 25 件物品,因为这是您可以获得的物品数量上限。要获得所有项目,您必须检查任何响应是否存在 NextToken
。如果有下一个令牌,您必须将它用于下一个请求,您将重复此操作,直到没有下一个令牌为止。
def lambda_handler(event, context):
workspaces_client_list = get_all_workspaces()
for workspaces_info in workspaces_client_list:
workspace_id = workspaces_info['WorkspaceId']
workspace_state = workspaces_info['State']
if workspace_state == 'STOPPED':
start_workspaces(workspace_id)
def get_all_workspaces():
response = workspaces.describe_workspaces()
workspaces_client_list = response['Workspaces']
while "NextToken" in response:
response = workspaces.describe_workspaces(NextToken=response['NextToken'])
workspaces_client_list.extend(response['Workspaces'])
return workspaces_client_list
我有以下用于启动工作区的脚本,但它获得了前 25 个工作区,尽管处于 AVAILABLE 或 STOPPED 状态。
我的环境中有 运行 超过 25 个工作区,我想弄清楚我需要添加什么,以便检查我环境中的所有工作区 (50<) 和对处于 STOPPED 状态的那些启动 START。
期待听到您的反馈。
谢谢
import boto3
workspaces = boto3.client('workspaces')
def lambda_handler(event, context):
workspaces_client_list = workspaces.describe_workspaces()
for workspaces_info in workspaces_client_list['Workspaces']:
workspace_id = workspaces_info['WorkspaceId']
workspace_state = workspaces_info['State']
if workspace_state == 'STOPPED':
start_workspaces(workspace_id)
def start_workspaces(workspace_id):
workspaces.start_workspaces(
StartWorkspaceRequests = [
{
'WorkspaceId': workspace_id
},
]
)
The documentation states 你可以在请求参数中提供一个Limit
Limit
The maximum number of items to return.
Type: Integer
Valid Range: Minimum value of 1. Maximum value of 25.
Required: No
您只能获得 25 件物品,因为这是您可以获得的物品数量上限。要获得所有项目,您必须检查任何响应是否存在 NextToken
。如果有下一个令牌,您必须将它用于下一个请求,您将重复此操作,直到没有下一个令牌为止。
def lambda_handler(event, context):
workspaces_client_list = get_all_workspaces()
for workspaces_info in workspaces_client_list:
workspace_id = workspaces_info['WorkspaceId']
workspace_state = workspaces_info['State']
if workspace_state == 'STOPPED':
start_workspaces(workspace_id)
def get_all_workspaces():
response = workspaces.describe_workspaces()
workspaces_client_list = response['Workspaces']
while "NextToken" in response:
response = workspaces.describe_workspaces(NextToken=response['NextToken'])
workspaces_client_list.extend(response['Workspaces'])
return workspaces_client_list