Triage and Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration of CloudFront web distributions not automatically compressing web content in AWS using the AWS console, please follow the below steps:
- Open the AWS Management Console and navigate to the CloudFront service.
- Select the distribution that needs to be remediated.
- Click on the “Behaviors” tab.
- Click on the “Create Behavior” button.
- In the “Create Behavior” dialog box, set the following values:
- Path Pattern: *
- Viewer Protocol Policy: Redirect HTTP to HTTPS
- Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
- Compress Objects Automatically: Yes
- Cache Based on Selected Request Headers: None
- Click on the “Create” button to create the new behavior.
- Wait for the distribution to update and propagate the changes.
Using CLI
Using CLI
To remediate the misconfiguration “CloudFront Web Distributions Should Automatically Compress Web Content” for AWS using AWS CLI, follow the below steps:
- Open the AWS CLI on your local machine.
-
Run the following command to get the ID of the distribution for which you want to enable automatic compression:
This will return a list of all your CloudFront distributions along with their IDs and domain names.
-
Once you have the distribution ID, run the following command to update the distribution configuration to enable automatic compression:
Replace
<distribution-id>
with the ID of the distribution you want to update. - After running the above command, the distribution configuration will be updated to enable automatic compression for web content.
-
Verify the changes by running the following command:
This will return the configuration of the default cache behavior for the distribution, which should now have the “Compress” property set to true.
Using Python
Using Python
To remediate the misconfiguration of CloudFront web distributions not automatically compressing web content in AWS using Python, you can follow these steps:
- Import the required AWS SDK modules using the following code:
- Create a boto3 client for CloudFront using the following code:
- Get a list of all CloudFront distributions using the following code:
- Iterate through each distribution and check if it has a default cache behavior with a gzip compression enabled using the following code:
- Save the Python script and run it to remediate the misconfiguration.