{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6205f0fb-db74-44d2-bfb1-98760790125c", "metadata": {}, "outputs": [ { "ename": "SyntaxError", "evalue": "invalid syntax (3925509796.py, line 1)", "output_type": "error", "traceback": [ "\u001b[0;36m Cell \u001b[0;32mIn[1], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m pip install boto3\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ "pip install boto3\n", "pip install pandas" ] }, { "cell_type": "code", "execution_count": null, "id": "4afe577f-283e-431a-8109-56228af5f203", "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import json\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "id": "80ea967b-3787-4c5a-b90b-692782bb9460", "metadata": {}, "outputs": [], "source": [ "# Initialize a session using your credentials\n", "session = boto3.Session(\n", " aws_access_key_id='AKIAZ3CL7RBT67UNF7CU',\n", " aws_secret_access_key='1C1gUZflYJ0Q8voiI4Iv+DBBXeLv0w9PQjOZm8Kr',\n", " region_name='us-west-2' # e.g., us-east-1\n", ")\n", "\n", "# Create an S3 client using the session\n", "s3 = session.client('s3')" ] }, { "cell_type": "code", "execution_count": null, "id": "b05018cb-03d4-4d47-9c60-149a8f73cf1c", "metadata": {}, "outputs": [], "source": [ "bucket_name = 'caetestbucket'\n", "\n", "try:\n", " contents = s3.list_objects(Bucket=bucket_name)['Contents']\n", " for item in contents:\n", " print(item['Key'])\n", "except NoCredentialsError:\n", " print(\"Credentials not available\")\n", "except KeyError:\n", " print(\"Bucket is empty or does not exist\")" ] }, { "cell_type": "code", "execution_count": null, "id": "028e3460-0485-4bfc-aa41-044276439838", "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import json\n", "\n", "file_key = 'MOCK_VEHICLE.json'\n", "\n", "response = s3.get_object(Bucket=bucket_name, Key=file_key)\n", "# Assuming each line in the file is a separate JSON object\n", "vehicle_data_lines = response['Body'].read().decode('utf-8').splitlines()\n", "\n", "vehicle_data = []\n", "for line in vehicle_data_lines:\n", " try:\n", " vehicle = json.loads(line)\n", " vehicle_data.append(vehicle)\n", " except json.JSONDecodeError as e:\n", " print(f\"Error decoding JSON: {e}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "4e4c78c3-bd9d-417e-9b96-9046cce33df2", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "ebc83569-2645-4f5d-a8c4-1192dd7aa72d", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "venv" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }