From 6356216c43f6d53e042a0e9738eac4fbd3f2eb99 Mon Sep 17 00:00:00 2001 From: Cevdet Date: Tue, 4 Mar 2025 17:25:51 +0300 Subject: [PATCH 1/4] Updated the logging module line and paginator max item --- python/example_code/ec2/hello/hello_ec2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/example_code/ec2/hello/hello_ec2.py b/python/example_code/ec2/hello/hello_ec2.py index c4aebf7a8b9..91ef18d7708 100644 --- a/python/example_code/ec2/hello/hello_ec2.py +++ b/python/example_code/ec2/hello/hello_ec2.py @@ -21,7 +21,8 @@ def hello_ec2(ec2_client): print("Hello, Amazon EC2! Let's list up to 10 of your security groups:") try: paginator = ec2_client.get_paginator("describe_security_groups") - response_iterator = paginator.paginate(MaxResults=10) + response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # I have changed 'MaxItems' : 10 with PaginationConfig={'MaxItems': 10} as the previous one was listing all the security groups. New version acts as expected and displays only 10 of our security groups. + logging.basicConfig(level=logging.INFO) # added this line because the default logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s") was displaying only blank line. After adding this line of code, the result was as expected. for page in response_iterator: for sg in page["SecurityGroups"]: logger.info(f"\t{sg['GroupId']}: {sg['GroupName']}") From 2300d8b977caa5d9a9f36da15c560c61d6f14c51 Mon Sep 17 00:00:00 2001 From: Rachel Hagerman <110480692+rlhagerm@users.noreply.github.com> Date: Wed, 5 Mar 2025 10:28:17 -0600 Subject: [PATCH 2/4] Updated comments. --- python/example_code/ec2/hello/hello_ec2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/example_code/ec2/hello/hello_ec2.py b/python/example_code/ec2/hello/hello_ec2.py index 91ef18d7708..c2736e04f18 100644 --- a/python/example_code/ec2/hello/hello_ec2.py +++ b/python/example_code/ec2/hello/hello_ec2.py @@ -21,8 +21,8 @@ def hello_ec2(ec2_client): print("Hello, Amazon EC2! Let's list up to 10 of your security groups:") try: paginator = ec2_client.get_paginator("describe_security_groups") - response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # I have changed 'MaxItems' : 10 with PaginationConfig={'MaxItems': 10} as the previous one was listing all the security groups. New version acts as expected and displays only 10 of our security groups. - logging.basicConfig(level=logging.INFO) # added this line because the default logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s") was displaying only blank line. After adding this line of code, the result was as expected. + response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # List only 10 security groups. + logging.basicConfig(level=logging.INFO) # Enable logging. for page in response_iterator: for sg in page["SecurityGroups"]: logger.info(f"\t{sg['GroupId']}: {sg['GroupName']}") From e749bf2ce976444878f664002d60ec130dea29a0 Mon Sep 17 00:00:00 2001 From: Cevdet Date: Tue, 4 Mar 2025 17:25:51 +0300 Subject: [PATCH 3/4] Updated the logging module line and paginator max item --- python/example_code/ec2/hello/hello_ec2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/example_code/ec2/hello/hello_ec2.py b/python/example_code/ec2/hello/hello_ec2.py index c4aebf7a8b9..91ef18d7708 100644 --- a/python/example_code/ec2/hello/hello_ec2.py +++ b/python/example_code/ec2/hello/hello_ec2.py @@ -21,7 +21,8 @@ def hello_ec2(ec2_client): print("Hello, Amazon EC2! Let's list up to 10 of your security groups:") try: paginator = ec2_client.get_paginator("describe_security_groups") - response_iterator = paginator.paginate(MaxResults=10) + response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # I have changed 'MaxItems' : 10 with PaginationConfig={'MaxItems': 10} as the previous one was listing all the security groups. New version acts as expected and displays only 10 of our security groups. + logging.basicConfig(level=logging.INFO) # added this line because the default logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s") was displaying only blank line. After adding this line of code, the result was as expected. for page in response_iterator: for sg in page["SecurityGroups"]: logger.info(f"\t{sg['GroupId']}: {sg['GroupName']}") From b3e30fd4e92c4e2a91fa35ae6c4bd048cf18879f Mon Sep 17 00:00:00 2001 From: Rachel Hagerman <110480692+rlhagerm@users.noreply.github.com> Date: Wed, 5 Mar 2025 10:28:17 -0600 Subject: [PATCH 4/4] Updated comments. --- python/example_code/ec2/hello/hello_ec2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/example_code/ec2/hello/hello_ec2.py b/python/example_code/ec2/hello/hello_ec2.py index 91ef18d7708..c2736e04f18 100644 --- a/python/example_code/ec2/hello/hello_ec2.py +++ b/python/example_code/ec2/hello/hello_ec2.py @@ -21,8 +21,8 @@ def hello_ec2(ec2_client): print("Hello, Amazon EC2! Let's list up to 10 of your security groups:") try: paginator = ec2_client.get_paginator("describe_security_groups") - response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # I have changed 'MaxItems' : 10 with PaginationConfig={'MaxItems': 10} as the previous one was listing all the security groups. New version acts as expected and displays only 10 of our security groups. - logging.basicConfig(level=logging.INFO) # added this line because the default logging.basicConfig(format="%(levelname)s:%(name)s:%(message)s") was displaying only blank line. After adding this line of code, the result was as expected. + response_iterator = paginator.paginate(PaginationConfig={'MaxItems': 10}) # List only 10 security groups. + logging.basicConfig(level=logging.INFO) # Enable logging. for page in response_iterator: for sg in page["SecurityGroups"]: logger.info(f"\t{sg['GroupId']}: {sg['GroupName']}")