File size: 3,493 Bytes
71502ca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | {
"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
}
|