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
Step: 1
To achieve this you can iterate through each log file in the S3 bucket download them locally read ea...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started