Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add connection templates first batch #2393

Merged
merged 18 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/assets/logos/Datetime.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/assets/logos/Twitter.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/assets/logos/Twitter.png
Binary file not shown.
629 changes: 629 additions & 0 deletions AWS/AWS_Get_cost_and_usage_by_service_and_type.ipynb

Large diffs are not rendered by default.

607 changes: 607 additions & 0 deletions AWS/AWS_Get_cost_forecast.ipynb

Large diffs are not rendered by default.

150 changes: 45 additions & 105 deletions AWS/AWS_Get_files_from_S3_bucket.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
]
},
"source": [
"# AWS - Get files from S3 bucket\n",
"# AWS - List objects from S3 bucket\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/AWS/AWS_Get_files_from_S3_bucket.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/Open_in_Naas_Lab.svg\"/></a><br><br><a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=AWS+-+Get+files+from+S3+bucket:+Error+short+description\">Bug report</a>"
]
},
Expand All @@ -37,7 +37,7 @@
]
},
"source": [
"**Tags:** #aws #cloud #storage #S3bucket #operations #snippet #url"
"**Tags:** #aws #cloud #storage #S3bucket #operations #snippet #list #objects"
]
},
{
Expand All @@ -61,7 +61,7 @@
"tags": []
},
"source": [
"**Last update:** 2023-04-12 (Created: 2021-09-20)"
"**Last update:** 2023-11-20 (Created: 2021-09-20)"
]
},
{
Expand All @@ -74,7 +74,7 @@
]
},
"source": [
"**Description:** This notebook provides a step-by-step guide to retrieving files from an Amazon Web Services (AWS) S3 bucket, allowing users to easily access their data stored in the cloud."
"**Description:** This notebook retrieves objects from an Amazon Web Services (AWS) S3 bucket, allowing users to easily access their data stored in the cloud."
]
},
{
Expand All @@ -97,34 +97,6 @@
"## Input"
]
},
{
"cell_type": "markdown",
"id": "a54c7458-f91d-4059-9abf-7a22882f6e9d",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
},
"source": [
"### Install packages"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c5b955a-86e6-495b-9dea-17d67937f010",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
},
"outputs": [],
"source": [
"!pip install boto3 getpass4"
]
},
{
"cell_type": "markdown",
"id": "464ad9fb-2dd8-4267-9e59-3bcf64b23b97",
Expand All @@ -135,7 +107,7 @@
]
},
"source": [
"### Import library"
"### Import libraries"
]
},
{
Expand All @@ -150,7 +122,12 @@
},
"outputs": [],
"source": [
"import boto3"
"import naas\n",
"try:\n",
" import boto3\n",
"except:\n",
" !pip install boto3 getpass4\n",
" import boto3"
]
},
{
Expand All @@ -163,7 +140,11 @@
]
},
"source": [
"### Variables"
"### Setup variables\n",
"**Mandatory**\n",
"- `aws_access_key_id`: This variable is used to store the AWS access key ID.\n",
"- `aws_secret_access_key`: This variable is used to store the AWS secret access key.\n",
"- `bucket_name`: The name of the S3 bucket from which you want to list the files."
]
},
{
Expand All @@ -178,11 +159,10 @@
},
"outputs": [],
"source": [
"ACCESS_KEY_ID = \"**********\"\n",
"SECRET_ACCESS_KEY = \"**********\"\n",
"\n",
"BUCKET_NAME = \"naas-example\"\n",
"BUCKET_OBJECT_KEY = \"naas_happy_hour.mp3\""
"# Mandatory\n",
"aws_access_key_id = naas.secret.get(\"AWS_ACCESS_KEY_ID\") or \"YOUR_AWS_ACCESS_KEY_ID\"\n",
"aws_secret_access_key = naas.secret.get(\"AWS_SECRET_ACCESS_KEY\") or \"YOUR_AWS_SECRET_ACCESS_KEY\"\n",
"bucket_name = \"naas-example\""
]
},
{
Expand All @@ -200,65 +180,52 @@
},
{
"cell_type": "markdown",
"id": "59711a37-d62a-4ad3-946c-1fefe7f134cd",
"id": "cf014bf3-7ae4-4758-93ee-37c3041db1cf",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
"awesome-notebooks/AWS/AWS_Daily_biling_notification_to_slack.ipynb"
]
},
"source": [
"### Get file"
"### Connect to AWS"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b3a6ca15-b5e7-46e7-b74f-438df9cb27db",
"id": "1a6b9c60-4462-406f-9a03-5354c37039f6",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
"tags": []
},
"outputs": [],
"source": [
"s3 = boto3.client(\n",
" \"s3\", aws_access_key_id=ACCESS_KEY_ID, aws_secret_access_key=SECRET_ACCESS_KEY\n",
")\n",
"fileObj = s3.get_object(Bucket=bucketname, Key=filename)"
"s3_client = boto3.client(\n",
" \"s3\",\n",
" aws_access_key_id=aws_access_key_id,\n",
" aws_secret_access_key=aws_secret_access_key\n",
")"
]
},
{
"cell_type": "markdown",
"id": "8ad0eac3-939c-49a9-85b0-415c6b13c24d",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
},
"id": "ef77d6ed-4118-4f11-be94-656e98d368bb",
"metadata": {},
"source": [
"### Generate pre-signed URL"
"### List objects in the S3 bucket"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d06823bd-23d8-4ca3-9c7b-95ebc9374b3c",
"id": "15fa4ea7-2f54-4c55-8ae9-8aea0df5a734",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
"tags": []
},
"outputs": [],
"source": [
"file_url = s3.generate_presigned_url(\n",
" \"get_object\",\n",
" Params={\"Bucket\": BUCKET_NAME, \"Key\": BUCKET_OBJECT_KEY},\n",
" ExpiresIn=604800,\n",
")"
"response = s3_client.list_objects_v2(Bucket=bucket_name)\n",
"print(\"Results:\", len(response['Contents']))"
]
},
{
Expand All @@ -274,34 +241,6 @@
"## Output"
]
},
{
"cell_type": "markdown",
"id": "40d3f1d6-f46e-4738-ac23-4e2f7472a755",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
},
"source": [
"### Display file"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ecb13f6-94e1-47c6-a80b-f753b1d0b7d9",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
},
"outputs": [],
"source": [
"fileOBJ"
]
},
{
"cell_type": "markdown",
"id": "18c8d442-dbff-4900-8048-3ab8a484367e",
Expand All @@ -318,16 +257,17 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fdcb928f-1a4d-481a-a635-29a59e035e48",
"id": "ac8286cf-a7d8-4ba1-be47-7a8f7007f4f9",
"metadata": {
"papermill": {},
"tags": [
"awesome-notebooks/AWS/AWS_Get_files_from_S3_bucket.ipynb"
]
"tags": []
},
"outputs": [],
"source": [
"file_url"
"# Process the response\n",
"if 'Contents' in response:\n",
" for file in response['Contents']:\n",
" file_name = file['Key']\n",
" print(file_name)"
]
}
],
Expand Down Expand Up @@ -362,4 +302,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
57 changes: 30 additions & 27 deletions AWS/AWS_Read_dataframe_from_S3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"tags": []
},
"source": [
"**Last update:** 2023-04-12 (Created: 2022-04-28)"
"**Last update:** 2023-11-20 (Created: 2022-04-28)"
]
},
{
Expand Down Expand Up @@ -101,11 +101,13 @@
},
"outputs": [],
"source": [
"import naas\n",
"try:\n",
" import awswrangler as wr\n",
"except:\n",
" !pip install awswrangler --user\n",
" import awswrangler as wr"
" import awswrangler as wr\n",
"from os import environ"
]
},
{
Expand All @@ -116,7 +118,11 @@
"tags": []
},
"source": [
"### Setup AWS"
"### Setup variables\n",
"**Mandatory**\n",
"- `aws_access_key_id`: This variable is used to store the AWS access key ID.\n",
"- `aws_secret_access_key`: This variable is used to store the AWS secret access key.\n",
"- `bucket_path`: The name of the S3 bucket from which you want to list the files."
]
},
{
Expand All @@ -129,13 +135,21 @@
},
"outputs": [],
"source": [
"# Credentials\n",
"AWS_ACCESS_KEY_ID = \"YOUR_AWS_ACCESS_KEY_ID\"\n",
"AWS_SECRET_ACCESS_KEY = \"YOUR_AWS_SECRET_ACCESS_KEY\"\n",
"AWS_DEFAULT_REGION = \"YOUR_AWS_DEFAULT_REGION\"\n",
"\n",
"# Bucket\n",
"BUCKET_PATH = f\"s3://naas-data-lake/dataset/\""
"# Mandatory\n",
"aws_access_key_id = naas.secret.get(\"AWS_ACCESS_KEY_ID\") or \"YOUR_AWS_ACCESS_KEY_ID\"\n",
"aws_secret_access_key = naas.secret.get(\"AWS_SECRET_ACCESS_KEY\") or \"YOUR_AWS_SECRET_ACCESS_KEY\"\n",
"bucket_path = f\"s3://naas-data-lake/example/\""
]
},
{
"cell_type": "markdown",
"id": "8105b836",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
Expand All @@ -153,7 +167,7 @@
"tags": []
},
"source": [
"### Setup Env"
"### Set environ"
]
},
{
Expand All @@ -166,20 +180,8 @@
},
"outputs": [],
"source": [
"%env AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID\n",
"%env AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY\n",
"%env AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
]
},
{
"cell_type": "markdown",
"id": "8105b836",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
"environ[\"AWS_ACCESS_KEY_ID\"] = aws_access_key_id\n",
"environ[\"AWS_SECRET_ACCESS_KEY\"] = aws_secret_access_key"
]
},
{
Expand All @@ -203,7 +205,8 @@
},
"outputs": [],
"source": [
"df = wr.s3.read_parquet(BUCKET_PATH, dataset=True)"
"df = wr.s3.read_parquet(bucket_path, dataset=True)\n",
"print(\"Rows:\", len(df))"
]
},
{
Expand Down Expand Up @@ -282,4 +285,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading