Skip to content

Instantly share code, notes, and snippets.

@shaposhnikoff
Created January 28, 2025 22:38
Show Gist options
  • Save shaposhnikoff/0b2889f1f25d55e5cd00799befd47d9c to your computer and use it in GitHub Desktop.
Save shaposhnikoff/0b2889f1f25d55e5cd00799befd47d9c to your computer and use it in GitHub Desktop.
import boto3
import datetime
client = boto3.client('acm',region_name='eu-central-1')
def list_certificates():
response = client.list_certificates()
return response['CertificateSummaryList']
def get_certificate_details(certificate_arn):
response = client.describe_certificate(
CertificateArn=certificate_arn
)
return response
def get_certificate_expiration_date(certificate_arn):
response = get_certificate_details(certificate_arn)
return response['Certificate']['NotAfter']
def get_days_to_expire(expiration_date):
expiration_date = expiration_date.replace(tzinfo=None)
return (expiration_date - datetime.datetime.now()).days
if __name__ == '__main__':
for cert in list_certificates():
print(cert['DomainName'],get_certificate_expiration_date(cert['CertificateArn']),get_days_to_expire(get_certificate_expiration_date(cert['CertificateArn'])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment