Best Python code snippet using localstack_python
lambda_function.py
Source:lambda_function.py
...10 11 print('begin get_resource_config_compliance_by_resource')12 13 try:14 r = config.get_compliance_details_by_resource(15 ResourceType=resource_type,16 ResourceId=resource_id,17 ComplianceTypes=[18 'COMPLIANT',19 'NON_COMPLIANT',20 # 'NOT_APPLICABLE',21 # 'INSUFFICIENT_DATA',22 ],23 )24 except ClientError as e:25 print(f"ClientError\n{e}")26 raise27 else:28 print(r)...
pullComplianceData.py
Source:pullComplianceData.py
...30 logger.info("Compliance Output is " + json.dumps(compliance_output))31 32 detailed_resource_output = []33 for resourceid in resource_ids:34 response = configsess.get_compliance_details_by_resource(ResourceType='AWS::S3::Bucket',ResourceId=resourceid)35 for ruleresult in response['EvaluationResults']:36 rule_eval_output = { 'AccountId': accountId, 'ResourceType': 'S3 Bucket', 'BucketCompliance': compliance_output[resourceid]['BucketCompliance'], 'ResourceId': resourceid, 'RuleCompliance': ruleresult['ComplianceType'], 'ConfigRuleName': ruleresult['EvaluationResultIdentifier']['EvaluationResultQualifier']['ConfigRuleName'] }37 rule_eval_output['ConfigRuleInvokedTime'] = str(ruleresult['ConfigRuleInvokedTime']) 38 if ruleresult['ComplianceType'] == 'NON_COMPLIANT':39 if 'Annotation' in ruleresult:40 rule_eval_output['Annotation'] = ruleresult['Annotation']41 else:42 rule_eval_output['Annotation'] = "No annotations for this rule are available"43 detailed_resource_output.append(rule_eval_output)44 logger.info("Detailed Resource Rule Compliance is " + json.dumps(detailed_resource_output))45 46 return (detailed_resource_output)47def lambda_handler(event, context):48 logger = logging.getLogger()...
s3_public_read_test.py
Source:s3_public_read_test.py
...27def test_s3_public_read_non_compliant():28 create_s3_public_bucket()29 time.sleep(5)30 client = boto3.client('config')31 response = client.get_compliance_details_by_resource(32 ResourceType = 'AWS::S3::Bucket',33 ResourceId = 'arctests3compliancepublicreadbucket',34 ComplianceTypes = ['NON_COMPLIANT']35 )36 assert response['EvaluationResults'][0]['ComplianceType'] == 'NON_COMPLIANT'37 delete_s3_public_bucket()38 time.sleep(5)39def create_s3_public_bucket():40 s3_client = boto3.client('s3')41 s3_client.create_bucket(Bucket='arctests3compliancepublicreadbucket')42 public_policy = """{43 "Version":"2008-10-17",44 "Statement":[{45 "Sid":"AllowPublicRead",...
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!!