Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

lambda function in python to shut ec2 at the time zone

import boto3
def lambda_handler(event, context):
    client = boto3.client('ec2')
    ec2_regions = [region['RegionName'] for region in client.describe_regions()['Regions']]
    for region in ec2_regions:
        ec2 = boto3.resource('ec2',region_name=region)
        instances = ec2.instances.filter(Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])
        RunningInstances = [instance.id for instance in instances]
        for i in RunningInstances:
            stoppingInstances = ec2.instances.stop(i)
            print(stoppingInstances)
NOTE- You may require indentation formatting if you use this code.
Comment

PREVIOUS NEXT
Code Example
Python :: how to do something daily python 
Python :: django view - apiview decorator (retrieve, update or delete - GET, PUT, DELETE) 
Python :: django check for empty onetoone exists 
Python :: wget http://xael.org/norman/python/python-nmap/pythonnmap- 0.2.4.tar.gz-On map.tar.gz 
Python :: using .get() for deep dictionary 
Python :: # remove sensitive information like name, email, phone no from text 
Python :: how to take input as an integer in python 
Python :: Python PEP (class) 
Python :: get primary key in get_context_data 
Python :: Python range Incrementing with the range using a positive step 
Python :: tuple python !g 
Python :: lsit to dataframe 
Python :: python get dataframe vlaues where cell is higher than 
Python :: tensorflow 1.x spp implementation 
Python :: ternary operator in list comprehension python 
Python :: block-all-mixed-content csp bypass python 
Python :: python 3.9.7 
Python :: python assert multiple conditions 
Python :: python while loop command gaming code 
Python :: np sign no 0 
Python :: element tree no able to find tag 
Python :: while loop using increment 
Python :: check string on substring godot 
Python :: update a variable in torch 
Python :: import sys execute cmd 
Python :: substituir valor simbólico por valor real em uma equação Python 
Python :: get picamera feed 
Python :: tuple merging 
Python :: python generator in while loop 
Python :: diamond shape alphabatical pattern program in python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =