Create Lambda function for Lightsail
Example of how to create a quick stop/start Lambda function for Lightsail in AWS
Code to STOP Lightsail Instance:
# TO STOP
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('lightsail', region_name='REGION-NAME')
response = client.stop_instance(
instanceName='INSTANCE-NAME'
)
return {
'statusCode': 200,
'body': json.dumps('Lambda has stopped instance')
}Code to START Lightsail Instance:
# TO START
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('lightsail', region_name='REGION-NAME')
response = client.start_instance(
instanceName='INSTANCE-NAME'
)
return {
'statusCode': 200,
'body': json.dumps('Lambda has started instance')
}t



Resources:
Last updated