Created
January 28, 2025 22:38
-
-
Save shaposhnikoff/0b2889f1f25d55e5cd00799befd47d9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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