> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Route 53 Domain Expiry In 45 Days

### More Info:

All the domain names registered with AWS Route 53 or transferred to AWS Route 53 should be renewed 45 days before their validity period ends.

### Risk Level

Low

### Address

Reliability, Security

### Compliance Standards

CBP

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the Route 53 Domain Expiry in 45 days issue on AWS using the AWS console, follow the below steps:

        1. Log in to the AWS Management Console and navigate to the Route 53 service.
        2. Click on the Registered Domains option from the left-hand menu.
        3. Select the domain name that is expiring in 45 days.
        4. Click on the Renew Domain button.
        5. Select the number of years you want to renew the domain for and click on the Add to cart button.
        6. Review the order details and click on the Complete Purchase button.
        7. Follow the on-screen instructions to complete the payment process.

        Once the payment process is complete, the domain will be renewed for the selected number of years and the Route 53 Domain Expiry issue will be resolved. It is recommended to set up auto-renewal for the domain to avoid such issues in the future.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the Route 53 Domain Expiry In 45 Days issue for AWS using AWS CLI, follow these steps:

        1. Open the AWS CLI and run the following command to get a list of your Route 53 domains and their expiration dates:

        ```
        aws route53domains list-domains
        ```

        2. Identify the domain that is expiring within the next 45 days.

        3. Renew the domain by running the following command:

        ```
        aws route53domains renew-domain --domain-name <domain_name> --duration-in-years <number_of_years>
        ```

        Replace `<domain_name>` with the name of the expiring domain and `<number_of_years>` with the number of years you want to renew the domain for.

        4. Verify that the domain has been renewed by running the following command:

        ```
        aws route53domains get-domain-detail --domain-name <domain_name>
        ```

        Replace `<domain_name>` with the name of the renewed domain.

        5. Check the new expiration date of the domain to ensure that it has been extended by the desired number of years.

        By following these steps, you should be able to successfully remediate the Route 53 Domain Expiry In 45 Days issue for AWS using AWS CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the Route 53 Domain Expiry issue in AWS using Python, you can follow the below steps:

        Step 1: Install the required Python libraries boto3 and datetime by running the following command in your terminal:

        ```
        pip install boto3 datetime
        ```

        Step 2: Create an AWS IAM user with programmatic access and Route 53 read-only access. Generate an access key and secret access key for the user.

        Step 3: In your Python script, import the required libraries and set up the AWS credentials using the access key and secret access key generated in Step 2:

        ```python theme={null}
        import boto3
        import datetime

        # Set up AWS credentials
        aws_access_key_id = 'YOUR_ACCESS_KEY_ID'
        aws_secret_access_key = 'YOUR_SECRET_ACCESS_KEY'
        client = boto3.client('route53', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
        ```

        Step 4: Use the `list_hosted_zones()` method to get a list of all the hosted zones in your AWS account:

        ```python theme={null}
        response = client.list_hosted_zones()
        hosted_zones = response['HostedZones']
        ```

        Step 5: Iterate through the hosted zones and use the `get_hosted_zone()` method to get the details of each hosted zone:

        ```python theme={null}
        for hosted_zone in hosted_zones:
            hosted_zone_id = hosted_zone['Id']
            hosted_zone_name = hosted_zone['Name']
            response = client.get_hosted_zone(Id=hosted_zone_id)
            hosted_zone_details = response['HostedZone']
        ```

        Step 6: Check the `Expiration` field in the `hosted_zone_details` dictionary to see if the domain is expiring in the next 45 days:

        ```python theme={null}
        expiration_date = hosted_zone_details['Expiration']
        expiration_date_obj = datetime.datetime.strptime(expiration_date, '%Y-%m-%dT%H:%M:%S.%fZ')
        today = datetime.datetime.utcnow()
        if (expiration_date_obj - today).days <= 45:
            print(f"The domain {hosted_zone_name} is expiring in {expiration_date_obj - today} days.")
        ```

        Step 7: If the domain is expiring in the next 45 days, you can take appropriate action such as renewing the domain or transferring it to another registrar.

        Note: You can schedule this Python script to run periodically using a cron job or a similar scheduling mechanism to ensure that you are notified of any expiring domains in a timely manner.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-restore-expired.html](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-restore-expired.html)
