Automate Start-Stop EC2 Instances Using Lambda - Step-by-Step Guide
In this informative video tutorial, we'll walk you through the process of automating the start and stop actions of your EC2 instances on Amazon Web Services (AWS) using AWS Lambda.
Throughout the video, we'll cover the following key points:
1. Introduction to AWS Lambda and its benefits in automating EC2 instance processes.
2. Setting up the AWS Management Console and creating a Lambda function.
3. Defining IAM roles and permissions for secure and seamless operations.
4. Configuring a scheduled event to trigger the Lambda function.
5. Writing the Lambda function code to start and stop EC2 instances.
6. Testing the function
By the end of this tutorial, you'll have a comprehensive understanding of how to leverage AWS Lambda to streamline your EC2 instance management and optimize your AWS resources efficiently.
Watch the video now and take control of your EC2 instances with automation powered by AWS Lambda. Subscribe to our channel for more AWS-related content and stay up-to-date with the latest cloud computing techniques!
Lambda code reference to stop EC2
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))
Lambda code reference to start EC2
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))
reference document link
repost.aws/knowledge-center/s...
Пікірлер: 31
Nice video man...please help us more
Many thanks.. It worked..
Thanks for explaining very nicely 🙏👍
many many many step-by-step and only tours worked perfectly fine.
Informative 👍
very good explanation
This is very informative . i tried and it works fine. thank you :)🙂
@user-su8wj4ey3x
10 ай бұрын
Hi Please can you give an insight on how you edited the Lambda function code?I can't copy and paste code. Showing i should use cloud9.
@Shaan9987
10 ай бұрын
@@user-su8wj4ey3x Just copy from aws official document of python script for lambda function and try 1 st with deploy and then test
@CloudPaathshala
10 ай бұрын
you can use lambda code generator from aws console itself
thanks bro
nice video bro keep it up dont stop uploading
@CloudPaathshala
6 ай бұрын
Thank you.
Hi Easy to follow and understand tutorial. Looks like one can't copy and paste code on Lambda anymore as you did on this tutorial. It showing i should use AWS cloud 9 to edit lambda function code.
@CloudPaathshala
10 ай бұрын
you can use code generator for same and write required code
instead of using cloudwatch, we can use eventbridge scheduler, by setting up the rate based timing schedule, to invoke the lambda function to turn on and off the EC2 instances right?
@user-mr5lx9hu7t
2 ай бұрын
now cw rule now added into the EventBridge
Hi am trying to stop and start 3 ec2 its giving error of client error instance id is malformed. But its working for single ec2. Please how to solve this
Do you have to create 2 functions 2 rules for both start & stop ? Waiting for your valuable response..
@CloudPaathshala
4 ай бұрын
Yes you can create 2 functions and 1 function is also enough where we can include other required rule as well.
@bhabanisanakrdas007
4 ай бұрын
@@CloudPaathshala it is good now
Hi how to monitor performance and availablity of ec2
@CloudPaathshala
9 ай бұрын
by using cloudwatch, you can watch my video on cloudwatch to monitor ec2
For monthly cost should be??
@CloudPaathshala
6 ай бұрын
monthly cost of any particular resource?
This is good stuff..
when it start again
Thanks
Hey I get an error: Response { "errorMessage": "2024-03-14T10:32:34.778Z c8640d39-6d77-4df5-8a9d-ea41a6db2300 Task timed out after 3.01 seconds" } what I could do wrong?
@toni9536
27 күн бұрын
Try going to configuration of the lambda function and increasing the timeout. It worked for me
For some reason it's not working for me, it gives me this message: Please Help [ERROR] NameError: name 'region_name' is not defined Traceback (most recent call last): File "/var/lang/lib/python3.12/importlib/__init__.py", line 90, in import_module