ManagedkdbInsights/boto/delete_db.ipynb (138 lines of code) (raw):
{
"cells": [
{
"cell_type": "markdown",
"id": "cddb91fd-4a0a-4128-952e-590db1ad5550",
"metadata": {},
"source": [
"# DELETE: Database"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c8ce4778-2140-42ab-87ea-c2ffd1479807",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# database name to delete\n",
"DATABASE_NAME=\"welcomedb\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3b86ed6-7e57-4f77-9871-772b861234b9",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"import boto3\n",
"import json\n",
"import datetime\n",
"\n",
"from managed_kx import *\n",
"from env import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19695e39-86c1-4952-8c70-0056f2bd512c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Using credentials and create service client\n",
"session = boto3.Session()\n",
"\n",
"# create finspace client\n",
"client = session.client(service_name='finspace')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f5c594c-b6e4-4ce6-ae83-9b254f68781d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"if DATABASE_NAME is not None:\n",
" try:\n",
" resp=client.get_kx_database(environmentId=ENV_ID, databaseName=DATABASE_NAME)\n",
" resp.pop('ResponseMetadata', None)\n",
" except client.exceptions.ResourceNotFoundException:\n",
" resp = f\"Database: {DATABASE_NAME} does not exist\"\n",
"\n",
" display(resp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7b5122ff-224f-458d-8d80-8817c0915098",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"if DATABASE_NAME is not None:\n",
" try:\n",
" resp=client.delete_kx_database(environmentId=ENV_ID, databaseName=DATABASE_NAME)\n",
" resp.pop('ResponseMetadata', None)\n",
" except client.exceptions.ResourceNotFoundException:\n",
" resp = f\"Database: {DATABASE_NAME} does not exist\"\n",
"\n",
" display(resp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1a5634e9-3184-4929-a57f-3ca826ced0c4",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"print( f\"Last Run: {datetime.datetime.now()}\" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72f6d6b6-cd58-4dec-9433-ba57ba0faf0c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "conda_python3",
"language": "python",
"name": "conda_python3"
},
"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.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}