{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3b5e979f",
   "metadata": {},
   "source": [
    "# Example Notebook: Working with AWS S3 Buckets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "863dc258",
   "metadata": {},
   "outputs": [],
   "source": [
    "import boto3\n",
    "\n",
    "s3 = boto3.client('s3')\n",
    "\n",
    "# List the objects in a specific bucket\n",
    "bucket_name = 'dev-cucumbers'\n",
    "objects = s3.list_objects(Bucket=bucket_name)['Contents']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22c829c5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "db550d37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'Key': '/Users/kale/PycharmProjects/swf-feed-ingestion/feed_ingestion/flows/deezer_marketshare/TheOrchard_202204_24947.zip',\n",
       "  'LastModified': datetime.datetime(2022, 12, 16, 12, 27, 34, tzinfo=tzlocal()),\n",
       "  'ETag': '\"8ac2b589a96522ac0aa014c891b79702\"',\n",
       "  'Size': 307043,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '/cache_stats/2019-11-10_cache_stats.png',\n",
       "  'LastModified': datetime.datetime(2019, 11, 11, 16, 10, 9, tzinfo=tzlocal()),\n",
       "  'ETag': '\"6ec5cf96eb6ef6741bc244e327bb5199\"',\n",
       "  'Size': 73950,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '/sme-labelcopy-bulk-ingest/staging/dev/2020-11-18T11-12-45Z-FBD0A2.input',\n",
       "  'LastModified': datetime.datetime(2020, 11, 18, 8, 15, 42, tzinfo=tzlocal()),\n",
       "  'ETag': '\"5118309c7cb0dc6bdc22cec17cba84f2\"',\n",
       "  'Size': 2340774,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '/tmp/ritmogestion-fixed.csv',\n",
       "  'LastModified': datetime.datetime(2022, 5, 13, 9, 3, 39, tzinfo=tzlocal()),\n",
       "  'ETag': '\"62f189c6a335da3ed1153c047b06e605\"',\n",
       "  'Size': 2330827,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '11c89/vendors/28777-1532518530.txt',\n",
       "  'LastModified': datetime.datetime(2018, 7, 25, 11, 33, 24, tzinfo=tzlocal()),\n",
       "  'ETag': '\"b563d0023856ce8bd4745e2996b9be4f\"',\n",
       "  'Size': 346,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '123.txt.gz',\n",
       "  'LastModified': datetime.datetime(2021, 1, 17, 15, 2, 22, tzinfo=tzlocal()),\n",
       "  'ETag': '\"c3baf1536dea7d1ef04a2e26ca76c279\"',\n",
       "  'Size': 28,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '2019-11-10_cache_stats.png',\n",
       "  'LastModified': datetime.datetime(2019, 11, 11, 16, 8, 9, tzinfo=tzlocal()),\n",
       "  'ETag': '\"6ec5cf96eb6ef6741bc244e327bb5199\"',\n",
       "  'Size': 73950,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '24072020/',\n",
       "  'LastModified': datetime.datetime(2020, 7, 24, 7, 59, 48, tzinfo=tzlocal()),\n",
       "  'ETag': '\"d41d8cd98f00b204e9800998ecf8427e\"',\n",
       "  'Size': 0,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '24072020/data_0_0_0.json',\n",
       "  'LastModified': datetime.datetime(2020, 7, 28, 13, 54, 14, tzinfo=tzlocal()),\n",
       "  'ETag': '\"178a2042f69dc83618c6ff5dd74d1e1c\"',\n",
       "  'Size': 2370,\n",
       "  'StorageClass': 'STANDARD'},\n",
       " {'Key': '3f231/vendors/28778-1532512597.txt',\n",
       "  'LastModified': datetime.datetime(2018, 7, 25, 9, 54, 31, tzinfo=tzlocal()),\n",
       "  'ETag': '\"62440daaf99ae2b4be6f5116ee7c8fbf\"',\n",
       "  'Size': 358,\n",
       "  'StorageClass': 'STANDARD'}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "objects[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bc2de225",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "File test_file_sagemaker.txt written to bucket dev-cucumbers/ml\n"
     ]
    }
   ],
   "source": [
    "# Set the file name and contents\n",
    "file_name = 'test_file_sagemaker.txt'\n",
    "file_contents = 'Hello, world from SageMaker!'\n",
    "\n",
    "# Write the file to the bucket\n",
    "s3.put_object(Body=file_contents, Bucket='dev-cucumbers', Key=file_name)\n",
    "\n",
    "print(f\"File {file_name} written to bucket dev-cucumbers/ml\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b03b7858",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7eef3c29",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_pytorch_p310",
   "language": "python",
   "name": "conda_pytorch_p310"
  },
  "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.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
