-2

i tried to find out the power-shell script for to download the previous days (1 day before)cloud front logs to my local host from s3 bucket. but didnt find any thing.

i got a request from my developer he need previous days log (24 hrs old) on daily basis to analyse the same.

Thanks in advance

Rishikesh
  • 1
  • 2
  • Just to clarify... Are you saying that you have access logs from Amazon CloudFront that are being stored in Amazon S3 and you would like a way to easily download the files for a particular period of time? How would you define the time period -- would you assume it is 24 hours prior to the time that the download is run, or would you like to provide a starting time? – John Rotenstein Dec 02 '18 at 02:14
  • yes, i have a access logs from Amazon CloudFront that are being stored in Amazon S3 and i would like a way to easily download the files which are created a day before. for eg: today is 02-DEC-2018 then i wanted to download all the logs which are created on 01-DEC-2018 only. – Rishikesh Dec 02 '18 at 09:45

1 Answers1

0

CloudFront access logs are stored in Amazon S3 with a filename format of:

bucket-name.s3.amazonaws.com/optional-prefix/distribution-ID.YYYY-MM-DD-HH.unique-ID.gz

Therefore, you could use the AWS Command-Line Interface (CLI) cp command to copy files with a particular prefix:

aws s3 cp s3://<bucket-name>/<optional-prefix>/ <localdir> --recursive --exclude "*" --include "<distribution-ID>.2018-12-01*"

(Values in need to be substituted.)

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • thanks John.. it works . :) how can i write a poweshell script so that i can schedule the same to download the 1 days old logs everyday automatically. – Rishikesh Dec 09 '18 at 10:39
  • On Windows, you can create a Scheduled Task to run a command file on a regular basis. – John Rotenstein Dec 09 '18 at 12:50
  • please help me with the command to download -1 day logs.because above command file will download the same file. i need to download the logs for eg: on 9-Dec-18 i want to download 8-Dec-18 and on 10-Dec-18 i want to download 9 Dec-2018. – Rishikesh Dec 09 '18 at 16:21
  • You can probably do a web search to find that. For example: [Powershell's Get-date: How to get Yesterday at 22:00 in a variable? - Stack Overflow](https://stackoverflow.com/questions/2433941/powershells-get-date-how-to-get-yesterday-at-2200-in-a-variable) – John Rotenstein Dec 09 '18 at 23:53