Best Python code snippet using localstack_python
test_config_service.py
Source:test_config_service.py
...6TEST_RESOURCE_TYPES = "AWS::EC2::Instance"7class TestConfigService(unittest.TestCase):8 def setUp(self):9 self.config_service_client = aws_stack.create_external_boto_client("config")10 def create_iam_role(self, iam_role_name):11 self.iam_client = aws_stack.create_external_boto_client("iam")12 assume_policy_document = {13 "Version": "2012-10-17",14 "Statement": [15 {"Action": "sts:AssumeRole", "Principal": {"Service": "lambda.amazonaws.com"}}16 ],17 }18 iam_role_arn = self.iam_client.create_role(19 RoleName=iam_role_name,20 AssumeRolePolicyDocument=json.dumps(assume_policy_document),21 )["Role"]["Arn"]22 return iam_role_arn23 def create_configuration_recorder(self, iam_role_arn):24 self.config_service_client.put_configuration_recorder(25 ConfigurationRecorder={26 "name": TEST_CONFIG_RECORDER_NAME,27 "roleARN": iam_role_arn,28 "recordingGroup": {29 "allSupported": False,30 "includeGlobalResourceTypes": False,31 "resourceTypes": [TEST_RESOURCE_TYPES],32 },33 }34 )35 def test_put_configuration_recorder(self):36 iam_role_name = "role-{}".format(short_uid())37 iam_role_arn = self.create_iam_role(iam_role_name)38 self.create_configuration_recorder(iam_role_arn)39 configuration_recorder_data = self.config_service_client.describe_configuration_recorders()[40 "ConfigurationRecorders"41 ]42 self.assertIn(TEST_CONFIG_RECORDER_NAME, configuration_recorder_data[0]["name"])43 self.assertIn(iam_role_arn, configuration_recorder_data[0]["roleARN"])44 self.assertIn(45 TEST_RESOURCE_TYPES, configuration_recorder_data[0]["recordingGroup"]["resourceTypes"]46 )47 self.assertEqual(1, len(configuration_recorder_data))48 self.config_service_client.delete_configuration_recorder(49 ConfigurationRecorderName=TEST_CONFIG_RECORDER_NAME50 )51 def test_put_delivery_channel(self):52 iam_role_name = "role-{}".format(short_uid())53 iam_role_arn = self.create_iam_role(iam_role_name)54 self.create_configuration_recorder(iam_role_arn)55 s3_client = aws_stack.create_external_boto_client("s3")56 test_bucket_name = f"test-bucket-{short_uid()}"57 s3_client.create_bucket(Bucket=test_bucket_name)58 sns_client = aws_stack.create_external_boto_client("sns")59 sns_topic_arn = sns_client.create_topic(Name="test-sns-topic")["TopicArn"]60 delivery_channel_name = "test-delivery-channel"61 self.config_service_client.put_delivery_channel(62 DeliveryChannel={63 "name": delivery_channel_name,64 "s3BucketName": test_bucket_name,65 "snsTopicARN": sns_topic_arn,66 "configSnapshotDeliveryProperties": {"deliveryFrequency": "Twelve_Hours"},67 }...
app.py
Source:app.py
...8with open('config.json', 'r') as cfg:9 cfg_data = json.load(cfg)10 11 # create IAM roles for glue, sfn, lambda12 lambda_role = pdc_stack.create_iam_role(cfg_data["lambda_iam"]["assume_role_policy_document"], cfg_data["lambda_iam"]["policy_document"], cfg_data["iam_tags"], "lambda_role")13 sfn_role = pdc_stack.create_iam_role(cfg_data["sfn_iam"]["assume_role_policy_document"], cfg_data["sfn_iam"]["policy_document"], cfg_data["iam_tags"], "sfn_role")14 glue_role = pdc_stack.create_iam_role(cfg_data["glue_iam"]["assume_role_policy_document"], cfg_data["glue_iam"]["policy_document"], cfg_data["iam_tags"], "glue_role")15 16 # create glue connection 17 create_glue_connection = pdc_stack.create_glue_connection(cfg_data["glue_connections"][0], cfg_data["availability_zone"], cfg_data["security_group_id_list"], cfg_data["subnet_id"])18 for job in cfg_data["jobs"]:19 # create glue jobs 20 create_raw_job = pdc_stack.create_glue_job(job["raw_jobs"]["script_location"], glue_role, job["raw_jobs"]["default_arguments"], "raw", job["raw_jobs"]["tags"], job["job_name"], cfg_data["glue_connections"])21 create_processed_job = pdc_stack.create_glue_job(job["procesed_jobs"]["script_location"], glue_role, job["procesed_jobs"]["default_arguments"], "processed", job["procesed_jobs"]["tags"], job["job_name"])22 create_lambda_func = pdc_stack.create_lambda_function(lambda_role, "s3_bucket", "s3_key", job["lambda_env_vars"], job["lambda_tags"], job["job_name"]) 23 create_sfn = pdc_stack.create_sfn(sfn_role, job["sfn"]["definition_string"], job["sfn"]["definition_substitutions"], job["tags"], job["job_name"])24 25 ...
dwh.py
Source:dwh.py
...19 config.read_file(open(config_path))20 handler = Handler(config)21 args = sys.argv[1:]22 if args[0] == 'test_iam_role':23 response = handler.create_iam_role()24 print(response)25 handler.remove_iam_role()26 if args[0] == 'test_redshift_cluster':27 handler.create_iam_role()28 response = handler.start_redshift_cluster()29 print(response)30 handler.stop_redshift_cluster()31 if args[0] == 'start_redshift_cluster':32 handler.create_iam_role()33 handler.start_redshift_cluster()34 if args[0] == 'stop_redshift_cluster':35 handler.stop_redshift_cluster()36 if args[0] == 'view_s3_bucket':37 handler.print_s3_contents(args[1])38 if args[0] == 'print_s3_json_object':39 handler.print_s3_object(args[1], args[2])40if __name__ == '__main__':...
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!!