in sim/mc_sim_blog.py [0:0]
def get_input_csv(bucket_name, file_name):
""" Download and read CSV file from an S3 bucket
:param bucket_name: Bucket in which CSV file is located
:param file_name: key name of the CSV file to read
:return: DataFrame constructed from CSV file
"""
s3 = boto3.client('s3')
response = s3.get_object(Bucket=bucket_name, Key=file_name)
status = response.get("ResponseMetadata", {}).get("HTTPStatusCode")
if status == 200:
print(f"Retrieved file {file_name} from bucket {bucket_name}")
return pd.read_csv(response.get("Body"), index_col=0)
else:
print(f"Error in retrieving file {file_name} from bucket {bucket_name}; {status}")
sys.exit(1)