我必须使用boto3在python中编写一个AWS lambda函数。该函数的主要目的是检测目录中所有不健康的工作区,并重新启动状态为不健康的工作区。
我创建了一个cloudwatch警报,它触发SNS,而SNS又触发lambda。我不知道如何使用python遍历目录中的工作区,这将检测不健康的状态。谁能提供我的样例代码在python,以便我可以写的lambda。
谢谢
import json
import boto3
client = boto3.client('workspaces')
def lambda_handler(event, context):
statusCode = 200
print("Alarm activated")
DirectoryId = "d-966714f11"
UnhealthyWorkspace = []
if(DirectoryId == 'd-966714f114'):
response = client.describe_workspaces(
WorkspaceIds = (should be in an array)
)
us = response["Contents"]
for i in us:
if(State == 'Unhealthy'):
print(i)
UnhealthyWorkspace.append(i)
response1 = client.reboot_workspaces(
RebootWorkspaceRequests=[
{
'WorkspaceId' : UnhealthyWorkspace
}
]
)
发布于 2021-07-09 07:33:59
使用describe_workspaces()检索所有工作区的列表。
然后,遍历工作空间列表并检查:State = 'UNHEALTHY'
https://stackoverflow.com/questions/68306621
复制相似问题