Best Python code snippet using localstack_python
client.py
Source:client.py
...91 def set_stack_policy(self, StackName: str, StackPolicyBody: str = None, StackPolicyURL: str = None):92 pass93 def signal_resource(self, StackName: str, LogicalResourceId: str, UniqueId: str, Status: str):94 pass95 def stop_stack_set_operation(self, StackSetName: str, OperationId: str) -> Dict:96 pass97 def update_stack(self, StackName: str, TemplateBody: str = None, TemplateURL: str = None, UsePreviousTemplate: bool = None, StackPolicyDuringUpdateBody: str = None, StackPolicyDuringUpdateURL: str = None, Parameters: List = None, Capabilities: List = None, ResourceTypes: List = None, RoleARN: str = None, RollbackConfiguration: Dict = None, StackPolicyBody: str = None, StackPolicyURL: str = None, NotificationARNs: List = None, Tags: List = None, ClientRequestToken: str = None) -> Dict:98 pass99 def update_stack_instances(self, StackSetName: str, Accounts: List, Regions: List, ParameterOverrides: List = None, OperationPreferences: Dict = None, OperationId: str = None) -> Dict:100 pass101 def update_stack_set(self, StackSetName: str, Description: str = None, TemplateBody: str = None, TemplateURL: str = None, UsePreviousTemplate: bool = None, Parameters: List = None, Capabilities: List = None, Tags: List = None, OperationPreferences: Dict = None, AdministrationRoleARN: str = None, ExecutionRoleName: str = None, OperationId: str = None, Accounts: List = None, Regions: List = None) -> Dict:102 pass103 def update_termination_protection(self, EnableTerminationProtection: bool, StackName: str) -> Dict:104 pass105 def validate_template(self, TemplateBody: str = None, TemplateURL: str = None) -> Dict:...
lambda_function.py
Source:lambda_function.py
1# File_name: lambda_function.py2# Purpose: Lambda function to stop all aws services that cost money in dev and test3# Author: Søren Wandrup-Bendixen4# Email: soren.wandrup-Bendixen@cybercom.com5# Created: 2019-07-016# Called from CloudWatch event rule scheduled : cron( 0 18,19 ? * * * ) 7# Total time to run per execution is 10 minutes. And is set to run twice a day. 8# To be developed9# https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/checklistforunwantedcharges.html10# stop_fargate11# Elastic Beanstalk is designed to ensure that all the resources that you need are running, which means that it automatically relaunches any services that you stop. To avoid this, you must terminate your Elastic Beanstalk environment before you terminate resources that Elastic Beanstalk has created12# Services Started in AWS OpsWorks13# If you use the AWS OpsWorks environment to create AWS resources, you must use AWS OpsWorks to terminate those resources or AWS OpsWorks restarts them. For example, if you use AWS OpsWorks to create an Amazon EC2 instance, but then terminate it by using the Amazon EC2 console, the AWS OpsWorks auto healing feature categorizes the instance as failed and restarts it. For more information, see AWS OpsWorks User Guide.14# stop_cloudfront (stop_stack_set_operation)15# stop_alexaforbusiness16# stop_llearning17# make snapshot of elastic search before delete18# stop_support root account, report if not free19import datetime20print ('Start time: ' + str(datetime.datetime.now()))21import json22import simple_notification 23import traceback24import get_list_of_possible_resources25import all_region_names26import stop_autoscaling27import stop_elb28import stop_ecs29import stop_eks30import stop_ec231import stop_nat_gateway32import stop_sagemaker33import stop_robomaker34import stop_rds35import stop_emr36import stop_dax37import stop_kinesis38import stop_kinesisanalytics 39import stop_elasticache40import stop_glue41import stop_elastisearch42import stop_dms43import stop_redshift44import stop_neptune45import stop_batch46import stop_personalize47import stop_shield48import stop_lightsail49import stop_sdb50import stop_dynamodb51import stop_datapipeline52import stop_qldb53import stop_vpc_endpoint54import stop_elastic_ip55import stop_secrets_manager56import stop_cloudwatch57def lambda_handler(event, context):58 RunningInstances = []59 instanceList = ''60 try: 61 # only in play when a list of clients is wanted. 62 #get_list_of_possible_resources.fail_with_list('?')63 region_names = all_region_names.get_list('ec2',event['region_set'])64 # region_names = ['eu-west-1'] # for simple one region testing; Ireland65 # region_names = ['us-east-1'] # for simple one region testing; N. Virginia66 # region_names = ['us-west-2'] # for simple one region testing; Oregon67 # region_names = ['eu-north-1'] # for simple one region testing; Stockholm68 # region_names = ['me-south-1'] # for simple one region testing; Bahrain69 # region_names = ['ap-east-1'] # for simple one region testing; Hongkong70 for region_name_ in region_names:71 # RunningInstances.append( str(event['region_set']) + '#' + region_name_ + '#' )72 print (region_name_ + ' time: ' + str(datetime.datetime.now()))73 stop_dynamodb.change_billing_mode('dynamodb', region_name_, RunningInstances)74 # You will still be charged for inactive pipelines. Not a lot but some75 #stop_datapipeline.inactivate_pipelines('datapipeline', region_name_, RunningInstances)76 stop_datapipeline.delete_pipelines('datapipeline', region_name_, RunningInstances)77 stop_qldb.delete_ledgers('qldb', region_name_, RunningInstances)78 stop_autoscaling.suspend_processes('autoscaling', region_name_, RunningInstances)79 stop_batch.disable_job_queues('batch', region_name_, RunningInstances)80 stop_emr.stop_clusters('emr', region_name_, RunningInstances) # Stop EMR before ec2's otherwise the ec2 of emr will be terminated individually81 stop_elb.delete_instances('elb', region_name_, RunningInstances) # Delete load balancers82 stop_elb.delete_instances('elbv2', region_name_, RunningInstances) # Delete load balancers83 stop_ecs.stop_instances('ecs', region_name_, RunningInstances) # Stop: Amazon Elastic Container Service (ECS)84 stop_eks.delete_clusters('eks', region_name_, RunningInstances) # Stop: Amazon Elastic Container Service for Kubernetes CreateOperation85 stop_ec2.stop_instances('ec2', region_name_, RunningInstances)86 stop_nat_gateway.delete_ec2_nat_gateways('ec2', region_name_, RunningInstances) # Stop: Amazon Elastic Compute Cloud NatGateway87 stop_sagemaker.stop_jobs('sagemaker', region_name_, RunningInstances)88 stop_robomaker.stop_jobs('robomaker', region_name_, RunningInstances)89 stop_lightsail.stop_instances('lightsail', region_name_, RunningInstances)90 stop_lightsail.stop_relational_databases('lightsail', region_name_, RunningInstances)91 stop_lightsail.autostart_relational_databases('lightsail', region_name_, RunningInstances)92 stop_rds.stop_instances('rds', region_name_, RunningInstances)93 stop_rds.autostart_instances('rds', region_name_, RunningInstances)94 stop_rds.stop_clusters('rds', region_name_, RunningInstances)95 stop_rds.autostart_clusters('rds', region_name_, RunningInstances)96 stop_rds.stop_clusters('docdb', region_name_, RunningInstances) # stop docdb - same logic as rds cluster97 stop_sdb.delete_domains('sdb', region_name_, RunningInstances) # stops simpleDb (deletes doains) started when performing debug of EMR!98 stop_dax.delete_clusters('dax', region_name_, RunningInstances)99 stop_kinesis.delete_streams('kinesis', region_name_, RunningInstances) 100 stop_kinesisanalytics.stop_applications('kinesisanalytics', region_name_, RunningInstances) 101 stop_elasticache.delete_clusters('elasticache', region_name_, RunningInstances)102 stop_glue.stop_jobs('glue', region_name_, RunningInstances)103 stop_elastisearch.delete_domains('es', region_name_, RunningInstances) # ElasticSearch104 stop_dms.delete_instances('dms', region_name_, RunningInstances) # Database Migration Service105 # stop_redshift.change_to_smallest('redshift', region_name_, RunningInstances) # As I see it either I have to delete the cluster or turn it into a single-node cluster. Cant just stop it.106 stop_redshift.delete_clusters('redshift', region_name_, RunningInstances) # As I see it either I have to delete the cluster or turn it into a single-node cluster. Cant just stop it.107 stop_neptune.delete_clusters('neptune', region_name_, RunningInstances) 108 stop_neptune.delete_instances('neptune', region_name_, RunningInstances)109 stop_personalize.delete_campaigns('personalize', region_name_, RunningInstances)110 stop_vpc_endpoint.delete_vpc_endpoints('ec2', region_name_, RunningInstances)111 # Elastiv ip's that are not in use cost 0.01$/hour112 stop_elastic_ip.release_inactive_elastic_ips('ec2', region_name_, RunningInstances)113 # A secret cost 0.4 $/months114 stop_secrets_manager.delete_secrets('secretsmanager', region_name_, RunningInstances)115 #stop_cloudwatch.delete_alarms('cloudwatch', region_name_, RunningInstances)116 # Global services 117 stop_shield.delete_advanced('shield', RunningInstances) # WAF shield118 if len(RunningInstances) > 0:119 instanceList = json.dumps(RunningInstances)120 simple_notification.send_info(instanceList)121 statusCode = 200122 except Exception as exception:123 if len(RunningInstances) > 0:124 instanceList = json.dumps(RunningInstances)125 simple_notification.send_info(instanceList + ' - exception ' + traceback.format_exc() )126 #raise exception 127 statusCode = 404128 print ('End time: ' + str(datetime.datetime.now()))129 return {130 "statusCode": statusCode,131 "body": instanceList ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!