Hands Lab Advent Calendar will continue this year as well
We use Workspaces, a service that provides AWS virtual desktops. Sometimes it falls with Unhealthy
\ It broke even though I didn't do anything /
Most of the time, if the load is temporarily applied and it goes down, restarting will usually help. That's why I have Lambda to restart for the time being Since it is written in Node.js, it supports version upgrades that occur frequently ...
It's a simple code, so I thought I'd rewrite it to python anyway.
I wondered why I was checking in order, I wondered if I would not restart by directly specifying the workspace Id that has a problem. Since it will be fetched from the alert information, I interpreted that I did not want to set an alert in CloudWatch for each workspace and did not change it
--Runtime Python 3.7 --Timeout 15 seconds
import boto3
sns = boto3.client('sns')
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 == 'UNHEALTHY':
reboot_workspaces(workspace_id)
def reboot_workspaces(workspace_id):
workspaces.reboot_workspaces(
RebootWorkspaceRequests = [
{
'WorkspaceId': workspace_id
},
]
)
No matter which language you choose, you will not be able to escape from version upgrade support, Recently, the flow of Python has come to our company, so it was nice to have the opportunity to write it.
Tomorrow is @fasahina!
Recommended Posts