Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix logging for Lambda functions in the privatelink-access pattern #1800

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions patterns/privatelink-access/lambdas/create_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __str__(self):
return '%s >>> %s' % (self.message, json.dumps(self.kwargs))

_ = StructuredMessage # optional, to improve readability
logging.basicConfig(level=logging.DEBUG, format='%(message)s')

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

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

# Add the extracted private IP address of the ENI as an IP target in the target group
try:
logger.info('IP address %s is identified as belonging to one of the cluster endpoint ENIs', ip)
response = ELBV2_CLIENT.register_targets(
TargetGroupArn = TARGET_GROUP_ARN,
Targets=[{
'Id': ip,
'Port': 443
}]
)
logging.info(_(response))
logger.info(_(response))
except Exception as e:
logging.error(_(e))
logger.error(_(e))
raise(e)
16 changes: 8 additions & 8 deletions patterns/privatelink-access/lambdas/delete_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def __str__(self):
return '%s >>> %s' % (self.message, json.dumps(self.kwargs))

_ = StructuredMessage # optional, to improve readability
logging.basicConfig(level=logging.DEBUG, format='%(message)s')

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

def handler(event, context):

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

if not targetHealthDescriptions:
logging.info("Did not find any TargetHealthDescriptions, quitting!")
logger.info("Did not find any TargetHealthDescriptions, quitting!")
return

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

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

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

if not unhealthyTargetsToDeregister:
logging.info("There are no unhealthy targets to deregister, quitting!")
logger.info("There are no unhealthy targets to deregister, quitting!")
return

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

try:
response = ELBV2_CLIENT.deregister_targets(
TargetGroupArn = TARGET_GROUP_ARN,
Targets=unhealthyTargetsToDeregister
)
logging.info(_(response))
logger.info(_(response))
except Exception as e:
logging.error(_(e))
logger.error(_(e))
raise(e)
Loading