> ## 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.

# AWS Account Should Use CloudFront CDN Service

### More Info:

AWS CloudFront Content Delivery Network (CDN) service should be used within your AWS account to secure and accelerate the delivery of your websites, media files or static resources.

### Risk Level

Medium

### Address

Security

### Compliance Standards

AWSWAF

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate this misconfiguration, you can follow the steps below:

        1. Log in to your AWS console and navigate to the CloudFront service.

        2. Click the "Create Distribution" button.

        3. Choose the type of distribution you want to create. For example, if you want to use CloudFront to deliver your website content, select "Web".

        4. Configure the settings for your distribution. This includes setting the origin, which is the location of your content, and configuring caching settings.

        5. Once you have configured your settings, click "Create Distribution" to create your CloudFront distribution.

        6. After your CloudFront distribution is created, you will need to update your DNS settings to point to your CloudFront distribution. This involves creating a CNAME record in your DNS that points to your CloudFront distribution.

        7. Finally, test your CloudFront distribution to ensure that your content is being delivered correctly.

        By following these steps, you can remediate the misconfiguration and begin using CloudFront to deliver your content.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration in AWS that the account should use CloudFront CDN service, you can follow the below steps using AWS CLI:

        1. Open the AWS CLI on your local machine.

        2. Run the following command to create a new CloudFront distribution:

        ```
        aws cloudfront create-distribution --distribution-config file://distribution-config.json
        ```

        Note: Replace `distribution-config.json` with the path to your CloudFront distribution configuration file.

        3. Update the DNS records for your domain to point to the CloudFront distribution.

        4. Wait for the DNS changes to propagate.

        5. Verify that your website is now being served through CloudFront by visiting your website and checking the response headers for the `X-Cache` header. If the header is present, it means that your website is being served through CloudFront.

        By following these steps, you can remediate the misconfiguration that your AWS account should use CloudFront CDN service.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration in AWS where the account should use CloudFront CDN service, you can use the following steps in Python:

        1. Import the necessary AWS SDK for Python (Boto3) library.

        ```
        import boto3
        ```

        2. Create a CloudFront client object using the `boto3.client()` method.

        ```
        cloudfront = boto3.client('cloudfront')
        ```

        3. Create a new CloudFront distribution using the `create_distribution()` method.

        ```
        response = cloudfront.create_distribution(
            DistributionConfig={
                'CallerReference': 'unique-id', # Specify a unique identifier for the distribution
                'DefaultRootObject': 'index.html', # Specify the default root object
                'Origins': {
                    'Quantity': 1,
                    'Items': [
                        {
                            'Id': 'my-bucket-origin', # Specify a unique identifier for the origin
                            'DomainName': 'my-bucket.s3.amazonaws.com', # Specify the S3 bucket domain name
                            'S3OriginConfig': {
                                'OriginAccessIdentity': '' # Specify the origin access identity
                            }
                        }
                    ]
                },
                'DefaultCacheBehavior': {
                    'TargetOriginId': 'my-bucket-origin', # Specify the origin identifier
                    'ForwardedValues': {
                        'QueryString': False, # Specify whether to forward query strings
                        'Cookies': {
                            'Forward': 'none' # Specify whether to forward cookies
                        }
                    },
                    'ViewerProtocolPolicy': 'redirect-to-https', # Specify the viewer protocol policy
                    'MinTTL': 0 # Specify the minimum TTL
                },
                'Comment': 'My CloudFront distribution', # Specify a comment for the distribution
                'Enabled': True # Specify whether the distribution is enabled
            }
        )
        ```

        4. Wait for the distribution to be deployed using the `wait_until()` method.

        ```
        cloudfront.get_waiter('distribution_deployed').wait(
            Id=response['Distribution']['Id'],
            WaiterConfig={
                'Delay': 30,
                'MaxAttempts': 50
            }
        )
        ```

        5. Update the DNS records to point to the CloudFront distribution using Route 53 or other DNS service.

        ```
        # Example using Route 53
        route53 = boto3.client('route53')

        response = route53.change_resource_record_sets(
            HostedZoneId='Z1234567890123', # Specify the hosted zone ID
            ChangeBatch={
                'Changes': [
                    {
                        'Action': 'UPSERT',
                        'ResourceRecordSet': {
                            'Name': 'example.com', # Specify the domain name
                            'Type': 'A',
                            'AliasTarget': {
                                'HostedZoneId': 'Z2FDTNDATAQYW2', # Specify the CloudFront hosted zone ID
                                'DNSName': 'd1234567890123.cloudfront.net', # Specify the CloudFront DNS name
                                'EvaluateTargetHealth': False
                            }
                        }
                    }
                ]
            }
        )
        ```

        By following these steps, you can remediate the misconfiguration in AWS where the account should use CloudFront CDN service using Python.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/)
