How to use list_buckets method in localstack

Best Python code snippet using localstack_python

test_policy.py

Source:test_policy.py Github

copy

Full Screen

1from chalice.policy import PolicyBuilder2from chalice.policy import diff_policies3def iam_policy(client_calls):4 builder = PolicyBuilder()5 policy = builder.build_policy_from_api_calls(client_calls)6 return policy7def assert_policy_is(actual, expected):8 # Prune out the autogen's stuff we don't9 # care about.10 statements = actual['Statement']11 for s in statements:12 del s['Sid']13 assert expected == statements14def test_single_call():15 assert_policy_is(iam_policy({'dynamodb': set(['list_tables'])}), [{16 'Effect': 'Allow',17 'Action': [18 'dynamodb:ListTables'19 ],20 'Resource': [21 '*',22 ]23 }])24def test_multiple_calls_in_same_service():25 assert_policy_is(iam_policy({'dynamodb': set(['list_tables',26 'describe_table'])}), [{27 'Effect': 'Allow',28 'Action': [29 'dynamodb:DescribeTable',30 'dynamodb:ListTables',31 ],32 'Resource': [33 '*',34 ]35 }])36def test_multiple_services_used():37 client_calls = {38 'dynamodb': set(['list_tables']),39 'cloudformation': set(['create_stack']),40 }41 assert_policy_is(iam_policy(client_calls), [42 {43 'Effect': 'Allow',44 'Action': [45 'cloudformation:CreateStack',46 ],47 'Resource': [48 '*',49 ]50 },51 {52 'Effect': 'Allow',53 'Action': [54 'dynamodb:ListTables',55 ],56 'Resource': [57 '*',58 ]59 },60 ])61def test_not_one_to_one_mapping():62 client_calls = {63 's3': set(['list_buckets', 'list_objects',64 'create_multipart_upload']),65 }66 assert_policy_is(iam_policy(client_calls), [67 {68 'Effect': 'Allow',69 'Action': [70 's3:ListAllMyBuckets',71 's3:ListBucket',72 's3:PutObject',73 ],74 'Resource': [75 '*',76 ]77 },78 ])79def test_can_diff_policy_removed():80 first = iam_policy({'s3': {'list_buckets', 'list_objects'}})81 second = iam_policy({'s3': {'list_buckets'}})82 assert diff_policies(first, second) == {'removed': {'s3:ListBucket'}}83def test_can_diff_policy_added():84 first = iam_policy({'s3': {'list_buckets'}})85 second = iam_policy({'s3': {'list_buckets', 'list_objects'}})86 assert diff_policies(first, second) == {'added': {'s3:ListBucket'}}87def test_can_diff_multiple_services():88 first = iam_policy({89 's3': {'list_buckets'},90 'dynamodb': {'create_table'},91 'cloudformation': {'create_stack', 'delete_stack'},92 })93 second = iam_policy({94 's3': {'list_buckets', 'list_objects'},95 'cloudformation': {'create_stack', 'update_stack'},96 })97 assert diff_policies(first, second) == {98 'added': {'s3:ListBucket', 'cloudformation:UpdateStack'},99 'removed': {'cloudformation:DeleteStack', 'dynamodb:CreateTable'},100 }101def test_no_changes():102 first = iam_policy({'s3': {'list_buckets', 'list_objects'}})103 second = iam_policy({'s3': {'list_buckets', 'list_objects'}})...

Full Screen

Full Screen

lambda_s3_tagging.py

Source:lambda_s3_tagging.py Github

copy

Full Screen

2from botocore.exceptions import ClientError3region = "us-east-1"4client = boto3.client('s3', region_name = region)5# -----------------LIST ALL THE BUCKETS6def list_buckets():7 try:8 response = client.list_buckets()9 buckets = []10 for i in response['Buckets']:11 buckets.append(i['Name'])12 return(buckets)13 except Exception as error:14 print(error)15# ------------------LIST TAGS FOR THE BUCKETS & LIST BUCKET WITHOUT tag:Name16list_buckets = list_buckets()17def get_bucket_tagging(list_buckets):18 try:19 for i in list_buckets:20 response = client.get_bucket_tagging(21 Bucket= i22 )23 tag_keys = {}24 tag_items = tag_keys.items()25 for j in response['TagSet']:26 tag_keys.update(j)27 no_name_bucket = []28 if tag_keys['Key'] != 'Name':29 no_name_bucket.append(i)30 return(no_name_bucket)...

Full Screen

Full Screen

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