AWS S3 can be used to distribute files to the public by configuring a public bucket, or by configuring public access to specific objects from within the bucket. S3 can also be used to host static websites.

You can choose to log access to objects in your S3 buckets just as you would if you're hosting it via a webserver by configuring Server access logging option for your S3 bucket. The log can be configured to be stored in another S3 bucket which preferably set to private.

Steps to log access to AWS S3 bucket and website:

  1. Create a private S3 bucket to store the access logs if you don't already have one.

  2. Go to S3 section in your AWS Console.

  3. Click on the S3 bucket that you want to log the access to.
  4. Click on the Permissions tab.

  1. Create a private S3 bucket to store the logs if you don't already have one.

  2. Go to your AWS S3 dashboard.

  3. Click on the S3 bucket that you want to enable log access.
  4. Click on the Properties tab.
  5. Click on the Server access logging card.

  6. Click on the Enable logging radio button.
  7. Select the target bucket to store the logs from the select list.
  8. 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.

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

  10. Go to the bucket that you've configured as the target to store the logs.

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

  12. 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" -