Question: Write code that downloads all of the log files ending in `.log` in an S3 bucket and counts the total number of HTTP errors in

Write code that downloads all of the log files ending in `.log` in an S3 bucket and counts the total number of HTTP errors in those logs.

Log lines are in the format `{"path": "/", status: 200}` or `{"path": "/", status: 404}`, for example. (This is JSON, and you can process it as such if you choose.)

Use the bucket `class6-logs`, the access key ID "AKIASUMBPHIPY6DLZ4C5", and the secret access key "JQdQIbxsRcipnoKFnsfse44SMRGouzz4tbAzTYbe".

Use the code below to get started:

Code-

import boto3

client = boto3.client(

's3',

aws_access_key_id="AKIASUMBPHIPY6DLZ4C5",

aws_secret_access_key="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",

)

resp = client.list_objects(Bucket='class6-logs')

client.download_file('class6-logs', resp['Contents'][0]

['Key'], 'downloaded_file')

# for object in resp['Contents']:

# print(object['Key'])

# print(resp['Contents'][0]['Key'])

Step by Step Solution

3.40 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To achieve this you can iterate through each log file in the S3 bucket download them locally read ea... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!