Code:
import boto3
region = 'us-west-1'
instances = ['i-0a25b4cbbbdxxxxx', 'i-0a5bf9b3aexxxxxx']
ec2 = boto3.client('ec2', region_name=region)
def lambda_handler(event, context):
ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))
Tired of manually starting and stopping your EC2 instances? In this video, we will show you how to automate it using AWS Lambda! 💡 Whether you want to save costs by shutting down idle instances or schedule auto-starts, this step-by-step guide has got you covered!
🔹 What you'll learn:
✅ Create an AWS Lambda function
✅ Start & stop EC2 instances automatically
✅ Use AWS IAM roles for secure access
✅ Schedule with AWS EventBridge (CloudWatch)
📌 Links & Resources:
👉 AWS Lambda Docs: https://docs.aws.amazon.com/lambda/
👍 Like, Share & Subscribe for more AWS automation tips! 🚀✨
Download
0 formats
No download links available.
Auto ON/OFF: Control Your EC2 with AWS Lambda! ⚡#aws #devops #cloudcomputing | NatokHD