Skip to content

Commit edcecee

Browse files
authored
fix: Fix logging for Lambda functions in the privatelink-access pattern (#1800)
1 parent eb2395e commit edcecee

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

patterns/privatelink-access/lambdas/create_eni.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __str__(self):
1717
return '%s >>> %s' % (self.message, json.dumps(self.kwargs))
1818

1919
_ = StructuredMessage # optional, to improve readability
20-
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
21-
20+
logger = logging.getLogger(__name__)
21+
logger.setLevel(logging.DEBUG)
2222

2323
def handler(event, context):
2424
# Only modify on CreateNetworkInterface events
@@ -27,14 +27,15 @@ def handler(event, context):
2727

2828
# Add the extracted private IP address of the ENI as an IP target in the target group
2929
try:
30+
logger.info('IP address %s is identified as belonging to one of the cluster endpoint ENIs', ip)
3031
response = ELBV2_CLIENT.register_targets(
3132
TargetGroupArn = TARGET_GROUP_ARN,
3233
Targets=[{
3334
'Id': ip,
3435
'Port': 443
3536
}]
3637
)
37-
logging.info(_(response))
38+
logger.info(_(response))
3839
except Exception as e:
39-
logging.error(_(e))
40+
logger.error(_(e))
4041
raise(e)

patterns/privatelink-access/lambdas/delete_eni.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def __str__(self):
1818
return '%s >>> %s' % (self.message, json.dumps(self.kwargs))
1919

2020
_ = StructuredMessage # optional, to improve readability
21-
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
22-
21+
logger = logging.getLogger(__name__)
22+
logger.setLevel(logging.DEBUG)
2323

2424
def handler(event, context):
2525

@@ -32,7 +32,7 @@ def handler(event, context):
3232
)['TargetHealthDescriptions']
3333

3434
if not targetHealthDescriptions:
35-
logging.info("Did not find any TargetHealthDescriptions, quitting!")
35+
logger.info("Did not find any TargetHealthDescriptions, quitting!")
3636
return
3737

3838
# Iterate over the list of TargetHealthDescriptions and extract the list of
@@ -54,7 +54,7 @@ def handler(event, context):
5454
)['NetworkInterfaces']
5555

5656
if not networkInterfaces:
57-
logging.info("Did not find any EKS API ENIs to compare with, quitting!")
57+
logger.info("Did not find any EKS API ENIs to compare with, quitting!")
5858
return
5959

6060
for networkInterface in networkInterfaces:
@@ -71,17 +71,17 @@ def handler(event, context):
7171
unhealthyTargetsToDeregister.append(unhealthyTarget)
7272

7373
if not unhealthyTargetsToDeregister:
74-
logging.info("There are no unhealthy targets to deregister, quitting!")
74+
logger.info("There are no unhealthy targets to deregister, quitting!")
7575
return
7676

77-
logging.info("Targets are to be deregistered: %s", unhealthyTargetsToDeregister)
77+
logger.info("Targets to be deregistered are: %s", unhealthyTargetsToDeregister)
7878

7979
try:
8080
response = ELBV2_CLIENT.deregister_targets(
8181
TargetGroupArn = TARGET_GROUP_ARN,
8282
Targets=unhealthyTargetsToDeregister
8383
)
84-
logging.info(_(response))
84+
logger.info(_(response))
8585
except Exception as e:
86-
logging.error(_(e))
86+
logger.error(_(e))
8787
raise(e)

0 commit comments

Comments
 (0)