AWS S3 can be used to distribute files for public access whether via public S3 buckets or via static website hosting. It's similar to hosting files via webservers except that you don't get the access logs the same way webservers provide by default.

You can configure logging for your S3 buckets with the following steps:

  1. Create a private S3 bucket to store the logs if you don't already have one.
    1. Go to your AWS S3 dashboard.
    2. Click on the S3 bucket bucket that you want to enable log access.
    3. Click on the Properties tab.
    4. Click on the Server access logging card.
    5. Click on the Enable logging radio button.
    6. Select the target bucket to store the logs from the select list.
    7. Add prefix name(optional) and click Save.

      The prefix will be prepended to the log file name and will be very helpful if you're using a single bucket to store logs from multiple sources.

  2. Test if access logging is configured correctly.
    1. Access bucket objects or S3 website.

      Example website url is as the following:

      simplified-guide.s3-website.us-east-1.amazonaws.com/oseems.png

      which is basically in the following format:

      <website-bucket-name>.s3-website.<region-name>-<availability-zone>.amazonaws.com/<object-name>
    2. Go to bucket that you've configured as the target to store the logs.
    3. Download the generated log files.

      The log files is not generated and made available in real time, so there will be some delay from accessing the bucket objects and seeing the logs generated.

    4. View the log files using your favorite text viewer or edit.
      47411d8baafa8cced757f771442e08849454857df58a341bfbcdf5bc22ea7be8 simplified-guide [18/Feb/2019:05:43:32 +0000] 112.120.201.145 - 381A22D2E282215C WEBSITE.GET.OBJECT index.html "GET / HTTP/1.1" 404 NoSuchKey 538 - 28 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" -
      47411d8baafa8cced757f771442e08849454857df58a341bfbcdf5bc22ea7be8 simplified-guide [18/Feb/2019:05:43:34 +0000] 112.120.201.145 - 64BED33D9CCEB6B7 WEBSITE.GET.OBJECT favicon.ico "GET /favicon.ico HTTP/1.1" 404 NoSuchKey 539 - 14 - "http://simplified-guide.s3-website.us-east-1.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" -
      47411d8baafa8cced757f771442e08849454857df58a341bfbcdf5bc22ea7be8 simplified-guide [18/Feb/2019:05:43:43 +0000] 112.120.201.145 - 560BDDE0527AC26F WEBSITE.GET.OBJECT oseems.png "GET /oseems.png HTTP/1.1" 200 - 31397 31397 12 11 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36" -
Discuss the article:

Comment anonymously. Login not required.

Share!