How to use get_bucket_website method in localstack

Best Python code snippet using localstack_python

bucket_website.py

Source: bucket_website.py Github

copy

Full Screen

...28error_file = 'error.html'29# 以下代码展示只设置主页与404页面的静态网站托管30bucket.put_bucket_website(BucketWebsite(index_file, error_file))31# 获取website配置32result = bucket.get_bucket_website()33print('get_bucket_website without redirect:')34print('result index_file:', result.index_file)35print('result error_file:', result.error_file)36bucket.delete_bucket_website()37# 以下代码展示镜像回源的网站托管配置,采用主备模式或者多站点模式38# 设置匹配规则39include_header1= ConditionInlcudeHeader('host', 'test.oss-cn-beijing-internal.aliyuncs.com')40include_header2 = ConditionInlcudeHeader('host', 'test.oss-cn-shenzhen-internal.aliyuncs.com')41condition1 = Condition(key_prefix_equals='key1', 42 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])43condition2 = Condition(key_prefix_equals='key2', 44 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])45# 设置跳转规则,46mirror_headers_set_1 = MirrorHeadersSet("myheader-key5","myheader-value5")47mirror_headers_set_2 = MirrorHeadersSet("myheader-key6","myheader-value6")48set_list = [mirror_headers_set_1, mirror_headers_set_2]49pass_list = ['myheader-key1', 'myheader-key2']50remove_list = ['myheader-key3', 'myheader-key4']51mirror_header = RedirectMirrorHeaders(pass_all=True, pass_list=pass_list, remove_list=remove_list, set_list=set_list)52# 使用主备源站模式, 使用mirror_url_slave,mirror_url_probe参数53redirect1 = Redirect(redirect_type=REDIRECT_TYPE_MIRROR, pass_query_string=False, mirror_url='http:/​/​www.test.com/​', 54 mirror_url_slave='http:/​/​www.slave.com/​', mirror_url_probe='http:/​/​www.test.com/​index.html', mirror_pass_query_string=False, 55 mirror_follow_redirect=True, mirror_check_md5=True, mirror_headers=mirror_header)56# 不指定备站57redirect2 = Redirect(redirect_type=REDIRECT_TYPE_MIRROR, mirror_url='http:/​/​www.test.com/​',58 mirror_pass_query_string=True, mirror_follow_redirect=True, mirror_check_md5=False)59# 可以设置一条或多条,本示例展示设置多条60rule1 = RoutingRule(rule_num=1, condition=condition1, redirect=redirect1)61rule2 = RoutingRule(rule_num=2, condition=condition2, redirect=redirect2)62website_set = BucketWebsite(index_file, error_file, [rule1, rule2])63bucket.put_bucket_website(website_set)64# 获取website配置65website_get = bucket.get_bucket_website()66print('get_bucket_website mirror type:')67print('indext_file:', website_get.index_file)68print('error_file:', website_get.error_file)69print('rule sum:', len(website_get.rules))70bucket.delete_bucket_website() 71# 以下代码展示阿里云CDN跳转以及外部跳转或者内部跳转的设置72include_header1= ConditionInlcudeHeader('host', 'test.oss-cn-beijing-internal.aliyuncs.com')73include_header2 = ConditionInlcudeHeader('host', 'test.oss-cn-shenzhen-internal.aliyuncs.com')74condition1 = Condition(key_prefix_equals='key3', 75 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])76condition2 = Condition(key_prefix_equals='key4', 77 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])78condition3 = Condition(key_prefix_equals='key5',79 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])80# AliCDN 81redirect1 = Redirect(redirect_type=REDIRECT_TYPE_ALICDN, pass_query_string=True, 82 replace_key_with='${key}.suffix', proto='http', http_redirect_code=302)83# External84redirect2 = Redirect(redirect_type=REDIRECT_TYPE_EXTERNAL, pass_query_string=False, replace_key_prefix_with='abc', 85 proto='https', host_name='oss.aliyuncs.com', http_redirect_code=302)86# Internal87redirect3 = Redirect(redirect_type=REDIRECT_TYPE_INTERNAL, pass_query_string=False, replace_key_with='${key}.suffix')88# 可以设置一条或多条规则,本示例展示设置多条89rule1 = RoutingRule(rule_num=1, condition=condition1, redirect=redirect1)90rule2 = RoutingRule(rule_num=2, condition=condition2, redirect=redirect2)91rule3 = RoutingRule(rule_num=3, condition=condition3, redirect=redirect3)92website_set = BucketWebsite(index_file, error_file, [rule1, rule2, rule3])93bucket.put_bucket_website(website_set)94# 获取website配置95website_get = bucket.get_bucket_website()96print('get_bucket_website other type:')97print('indext_file:', website_get.index_file)98print('error_file:', website_get.error_file)99print('rule sum:', len(website_get.rules))100for rule in website_get.rules:101 print('rule_num:{}, redirect_type:{}'.format(rule.rule_num, rule.redirect.redirect_type))...

Full Screen

Full Screen

test_main.py

Source: test_main.py Github

copy

Full Screen

...13 except ClientError:14 return False15def get_website_information(bucket_name):16 try:17 response = s3_client.get_bucket_website(Bucket=bucket_name)18 return True, response['RedirectAllRequestsTo']['HostName']19 except ClientError:20 return False, None21def get_encryption_information(bucket_name):22 try:23 s3_client.get_bucket_encryption(Bucket=bucket_name)24 return True25 except ClientError:26 return False27class TestingMain(unittest.TestCase):28 def test_format_two_decimal_points(self):29 self.assertEqual('123.00', format_two_decimal_points(123))30 self.assertEqual('12345.68', format_two_decimal_points(12345.6789))31 def test_get_public_access_information(self):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful