AWS LAMBDA | START & STOP EC2 INSTANCE USING LAMBDA | CLOUD FLAIR

Опубликовано: 14 Апрель 2025
на канале: Cloud Flair
112
9

#awslambda #cloudflair #ec2 #aws #pune

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers, creating workload-aware cluster scaling logic, maintaining event integrations, or managing runtimes. With Lambda, you can run code for virtually any type of application or backend service - all with zero administration. Just upload your code as a ZIP file or container image, and Lambda automatically and precisely allocates compute execution power and runs your code based on the incoming request or event, for any scale of traffic.


Example function code—starting EC2 instances

import boto3
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))


Example function code—stopping EC2 instances

import boto3
region = 'us-west-1'
instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26']
ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))


You can take a look here to set cron expression values: https://docs.aws.amazon.com/lambda/la...

#javascript #aws #awslambda #serverless #100daysofcode #webdev #webdevelopment