I need your one more help can you please help me out: Q. How can I getcustomised email notifications when someone creates an EC2 instance that’s not nano, micro, small or medium? can you please help me out...
Please refer to this video - ua-cam.com/video/XGkm2BwNpyI/v-deo.html For your requireement, the flow will be - EC2 Service -> listen to EC2 create instance events in Eventbridge --> Trigger lambda --> Send email to an group or whoever you want.
No you cannot do it without a compute instance. you need a way to run some code which will trigger the shutdown command to the correct set of instances and thats where lambda's come in. They are on demand and you only pay for the time it is running, so it actually very cost effective.
yeah, you can do it without using a lambda... no compute, just use event bridge for EC2 stop (not lambda), obviously you need IAM Role for your Scheduler (trusted policy for scheduler and IAM policy for actions on ec2) .... and you have a EC2 scheduler without lambda now guy :)
If you know the list of ec2 instance id's then you can run the following aws command - aws ec2 start-instances --instance-ids i-INSTANCE_ID1 i-INSTANCE_ID2 i-INSTANCE_ID3
@@AWSTrainingByGauravAgrawal Sure I can use that, however, I would like a script like you mentioned Python script, for example, to shut down the instance and I would use multiple instance IDs to auto-start the instance. Is it possible to get a complete Python script to auto-start the instance? it will be very helpful for me
@@that_epics use the below python lambda code import boto3 def lambda_handler(event, context): # Create a Boto3 EC2 client ec2 = boto3.client('ec2') # Describe all instances in your account instances = ec2.describe_instances() # Extract instance IDs from the response instance_ids = [] for reservation in instances['Reservations']: for instance in reservation['Instances']: instance_ids.append(instance['InstanceId']) # Start all instances if instance_ids: ec2.start_instances(InstanceIds=instance_ids) return f'Starting instances: {instance_ids}' else: return 'No instances to start' # Note: Make sure that your Lambda function has the appropriate IAM permissions to describe and start EC2 instances.
@@AWSTrainingByGauravAgrawalSorry I am bothering you but where is the name of the tag like start=true and where I can mention only two or three examples of the ID is only.
great video! helped me out a lot. was using event scheduler as a starting point and the process just seemed so confusing! many thanks
Glad it helped!
Any idea how I can see the logs? When I go to cloudwatch logs I get error saying the log group does not exist
I need your one more help can you please help me out:
Q. How can I getcustomised email notifications when someone creates an EC2 instance that’s not nano, micro, small or medium? can you please help me out...
Please refer to this video - ua-cam.com/video/XGkm2BwNpyI/v-deo.html
For your requireement, the flow will be - EC2 Service -> listen to EC2 create instance events in Eventbridge --> Trigger lambda --> Send email to an group or whoever you want.
Is it possible to do that directly without using a lambda for shutting down ec2?
No you cannot do it without a compute instance. you need a way to run some code which will trigger the shutdown command to the correct set of instances and thats where lambda's come in. They are on demand and you only pay for the time it is running, so it actually very cost effective.
we can do it with Azure DevOps pipeline completely free
yeah, you can do it without using a lambda... no compute, just use event bridge for EC2 stop (not lambda), obviously you need IAM Role for your Scheduler (trusted policy for scheduler and IAM policy for actions on ec2) .... and you have a EC2 scheduler without lambda now guy :)
please give me a script for how to start multiple EC2 instances?
If you know the list of ec2 instance id's then you can run the following aws command -
aws ec2 start-instances --instance-ids i-INSTANCE_ID1 i-INSTANCE_ID2 i-INSTANCE_ID3
@@AWSTrainingByGauravAgrawal Sure I can use that, however, I would like a script like you mentioned Python script, for example, to shut down the instance and I would use multiple instance IDs to auto-start the instance. Is it possible to get a complete Python script to auto-start the instance? it will be very helpful for me
@@that_epics use the below python lambda code
import boto3
def lambda_handler(event, context):
# Create a Boto3 EC2 client
ec2 = boto3.client('ec2')
# Describe all instances in your account
instances = ec2.describe_instances()
# Extract instance IDs from the response
instance_ids = []
for reservation in instances['Reservations']:
for instance in reservation['Instances']:
instance_ids.append(instance['InstanceId'])
# Start all instances
if instance_ids:
ec2.start_instances(InstanceIds=instance_ids)
return f'Starting instances: {instance_ids}'
else:
return 'No instances to start'
# Note: Make sure that your Lambda function has the appropriate IAM permissions to describe and start EC2 instances.
@@AWSTrainingByGauravAgrawalSorry I am bothering you but where is the name of the tag like start=true and where I can mention only two or three examples of the ID is only.
Earlier script you mentioned tags to stop each instance