Skip to content

Commit 6f1f976

Browse files
AlistairP AWSrenlon
authored andcommitted
Address PR review feedback
1 parent 4132256 commit 6f1f976

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

alb-trust-store-monitoring/cloudformation-template.yaml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Resources:
165165
# CloudWatch Log Group for Lambda Function
166166
ALBTrustStoreMonitoringLogGroup:
167167
Type: AWS::Logs::LogGroup
168+
DeletionPolicy: Delete
168169
Properties:
169170
LogGroupName: '/aws/lambda/ALB-TrustStore-Monitoring'
170171
RetentionInDays: !Ref LogRetentionDays
@@ -209,7 +210,7 @@ Resources:
209210
import os
210211
import logging
211212
import urllib.request
212-
from datetime import datetime
213+
from datetime import datetime, timezone
213214
from cryptography import x509
214215
from cryptography.hazmat.backends import default_backend
215216
@@ -338,7 +339,7 @@ Resources:
338339
cert_pem = b'-----BEGIN CERTIFICATE-----' + cert_pem
339340
try:
340341
cert = x509.load_pem_x509_certificate(cert_pem, default_backend())
341-
subject_der = cert.subject.public_bytes(default_backend())
342+
subject_der = cert.subject.public_bytes()
342343
total_size += len(subject_der) + 2
343344
except:
344345
pass
@@ -426,7 +427,7 @@ Resources:
426427
return False
427428
428429
def lambda_handler(event, context):
429-
execution_timestamp = datetime.utcnow()
430+
execution_timestamp = datetime.now(timezone.utc)
430431
431432
retry_config = Config(
432433
retries={
@@ -443,9 +444,11 @@ Resources:
443444
# Update alarm thresholds based on current Service Quotas
444445
update_alarm_thresholds()
445446
446-
# Get all trust stores
447-
response = elbv2.describe_trust_stores()
448-
trust_stores = response.get('TrustStores', [])
447+
# Get all trust stores (paginated)
448+
trust_stores = []
449+
paginator = elbv2.get_paginator('describe_trust_stores')
450+
for page in paginator.paginate():
451+
trust_stores.extend(page.get('TrustStores', []))
449452
450453
if not trust_stores:
451454
return {
@@ -517,6 +520,8 @@ Resources:
517520
SourceArn: !GetAtt ALBTrustStoreMonitoringScheduleRule.Arn
518521

519522
# CloudWatch Alarm for NumberOfCaCertificates
523+
# Initial Threshold is a safe default; the Lambda dynamically updates it
524+
# based on the Service Quota value and the configured threshold percentage.
520525
NumberOfCaCertificatesAlarm:
521526
Type: AWS::CloudWatch::Alarm
522527
Properties:
@@ -530,7 +535,7 @@ Resources:
530535
ReturnData: true
531536
EvaluationPeriods: 1
532537
DatapointsToAlarm: 1
533-
Threshold: 500
538+
Threshold: 500 # Safe placeholder until Lambda updates it based on Service Quota and configured threshold percentage
534539
ComparisonOperator: 'GreaterThanThreshold'
535540
AlarmActions: !If
536541
- EnableSNSNotifications
@@ -543,6 +548,8 @@ Resources:
543548
TreatMissingData: 'notBreaching'
544549

545550
# CloudWatch Alarm for TotalRevokedEntries
551+
# Initial Threshold is a safe default; the Lambda dynamically updates it
552+
# based on the Service Quota value and the configured threshold percentage.
546553
TotalRevokedEntriesAlarm:
547554
Type: AWS::CloudWatch::Alarm
548555
Properties:
@@ -556,7 +563,7 @@ Resources:
556563
ReturnData: true
557564
EvaluationPeriods: 1
558565
DatapointsToAlarm: 1
559-
Threshold: 1000000
566+
Threshold: 1000000 # Safe placeholder until Lambda updates it based on Service Quota and configured threshold percentage
560567
ComparisonOperator: 'GreaterThanThreshold'
561568
AlarmActions: !If
562569
- EnableSNSNotifications
@@ -569,6 +576,8 @@ Resources:
569576
TreatMissingData: 'notBreaching'
570577

571578
# CloudWatch Alarm for TotalSubjectSize
579+
# Initial Threshold is a safe default; the Lambda dynamically updates it
580+
# based on the Service Quota value and the configured threshold percentage.
572581
TotalSubjectSizeAlarm:
573582
Type: AWS::CloudWatch::Alarm
574583
Properties:
@@ -582,7 +591,7 @@ Resources:
582591
ReturnData: true
583592
EvaluationPeriods: 1
584593
DatapointsToAlarm: 1
585-
Threshold: 20000
594+
Threshold: 20000 # Safe placeholder until Lambda updates it based on Service Quota and configured threshold percentage
586595
ComparisonOperator: 'GreaterThanThreshold'
587596
AlarmActions: !If
588597
- EnableSNSNotifications

0 commit comments

Comments
 (0)