{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# tutorial31,how to disable aws ec2 instance termination using boto3 python" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "ec2_client=boto3.client(\"ec2\")" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'ResponseMetadata': {'RequestId': '114129c2-db14-472d-809b-0dad7b7745e3',\n", " 'HTTPStatusCode': 200,\n", " 'HTTPHeaders': {'x-amzn-requestid': '114129c2-db14-472d-809b-0dad7b7745e3',\n", " 'content-type': 'text/xml;charset=UTF-8',\n", " 'content-length': '247',\n", " 'date': 'Fri, 06 Nov 2020 18:37:06 GMT',\n", " 'server': 'AmazonEC2'},\n", " 'RetryAttempts': 0}}" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ec2_client.modify_instance_attribute(InstanceId='i-058fafa0cf76e7d3e',DisableApiTermination={\n", " 'Value': True\n", " })" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'TerminatingInstances': [{'CurrentState': {'Code': 32,\n", " 'Name': 'shutting-down'},\n", " 'InstanceId': 'i-058fafa0cf76e7d3e',\n", " 'PreviousState': {'Code': 16, 'Name': 'running'}}],\n", " 'ResponseMetadata': {'RequestId': 'a1a61dbd-51d8-482f-92eb-a9bf1381edf2',\n", " 'HTTPStatusCode': 200,\n", " 'HTTPHeaders': {'x-amzn-requestid': 'a1a61dbd-51d8-482f-92eb-a9bf1381edf2',\n", " 'content-type': 'text/xml;charset=UTF-8',\n", " 'transfer-encoding': 'chunked',\n", " 'vary': 'accept-encoding',\n", " 'date': 'Fri, 06 Nov 2020 18:37:20 GMT',\n", " 'server': 'AmazonEC2'},\n", " 'RetryAttempts': 0}}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ec2_client.terminate_instances(InstanceIds=[\n", " 'i-058fafa0cf76e7d3e',\n", " ])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }