Boto3 Ec2 Resource

Let’s see how we can use Python and the boto3 library with EC2. In this course, you will journey with Seth Godin teaches you how to implement EC2 and VPC resources on AWS using Python API - Boto3! Implement your infrastructure with code. In previous section we initialized our EC2 resource using boto3 module which acts as a proxy to default session # Get EC2 resource ec2 = boto3. I am developing a simple python script to add rules to securitygroups, and I am wondering what is the difference between the two methods available within boto3: authorize_security_group_ingress(**k. Here are the examples of the python api boto3. Nowadays, I am juggling with Python-Boto3/Lambda. get unused AMIs using boto3 witn AWS Lambda. Masterclass 1. The following are code examples for showing how to use boto3. Moto - Mock AWS Services. This is like a handle to the EC2 console that we can use in our script. Doing this manually is an overhead and if you have multiple servers, this will be cumbersome. In this article I have covered how to use the AWS Python SDK library Boto3 to interact with EC2 resources. View Shutdown from COMPUTER SCIENCE 142523 at MGM's College of Engineering and Technology. Setting this up requires configuring an IAM role, setting a CloudWatch rule, and creating a Lambda function. The only rule I learned in a year of using the AWS API is to look in both places, and create both a client and a resource. import boto3 from boto3 import Session def connect_sts(region, role_arn): sts_client = boto3. I haven't used AWS, Amazon EC2 or boto3, so I can only guess what "instance" means in this case. js, Java and Python. This is the third and final part in a three part series where we build up a CloudFormation tempate for what I like to think of as a pretty typical environment: one virtual private cloud broken into two subnets and including two instances. Here are the examples of the python api boto3. I demonstrate how to automate the operational management tasks to AMI image backup creation for EC2 instances and subsequent clean up of those backup images using scheduled cron jobs on either a dedicated server or using AWS Lambda. import boto3 s3 = boto3. resource ('ec2', region_name = "ap-southeast-2") A list of regions with codes can be found here; The first section of code creates a KeyPair to be assigned to the created instances. client taken from open source projects. resource('s3') Because default session is limit to the profile or instance profile used, sometime you need to use the custom session to override the default session configuration (e. , dev/test environments). ec2 = boto3. It enables Python developers to create, configure, and manage AWS services, such as EC2 and S3. Here are 2 sample functions to illustrate how you can get information about Tags on instances using Boto3 in AWS. Boto3 comes with 'waiters', which automatically poll for pre-defined status changes in AWS resources. The resource Type is used to identify a boto3 client and the method of that client to execute. First, we'll import the boto3 library. resource('ec2') ec2. resource ('ec2', region_name = "ap-southeast-2"). resource ('s3') Every resource instance has a number of attributes and methods. Parameters resource_name ( string ) -- Name of the resource to look up. Here are 2 sample functions to illustrate how you can get information about Tags on instances using Boto3 in AWS. I think of it as being at a ‘higher’ level than the client. ec2 = boto3. If you launch an ec2 instance in the private subnet (first subnet – 10. Finally, we’ll use the EC2 resource to get all of the instances and then print their instance ID and state. Going forward, API updates and all new feature work will be focused on Boto3. Overview In this post, we'll cover how to automate EBS snapshots for your AWS infrastructure using Lambda and CloudWatch. awscli is boto-based. It seems Boto3 has two types of interfaces, clients and resources. stop() #for stopping an ec2 instance ec2. terminate() #for terminating an ec2 instance. A basic boto3 based tool for retrieving information from running EC2 instances. This function should be run at least daily. Use virtualenv to create the Python environment. Learn to implement EC2 and VPC resources on AWS using Python API, Boto3, and launch your own infrastructure on AWS. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. , dev/test environments). boto3 will use the same configuration files. Let’s see how we can use Python and the boto3 library with EC2. Right now I am looking for ec2 instances type limits for a given region. readthedocs. Session(region_name='', aws_access_key_id='', aws_secret_access_key=''). We use cookies for various purposes including analytics. resource('ec2') def lambda_handler(event, context): # Use the filter() method of the instances collection to retrieve # all running EC2 instances. import boto3 def get_instance_name(fid): # When given an instance ID as str e. This is a simple python boto3 script to get status and along with that you will get , how to choose resource or client for your operations. resource(resourcename) for higher level service access. An instance is automatically unlinked from a VPC when it's stopped - you can link it to the VPC again when. How to configure python boto3 SDK for AWS. In this article I will show you how to create AWS Lambda using Python to stop EC2 instances in all regions in one go. Launching an EC2 instance. resource('ec2') ec2client = boto3. I hope that this simple example will be helpful for you. resource('ec2', region_name='us-west-2') It is often confusing what functionality is in client and what is in resource. " The good news is that Boto 3 is extremely well documented. We wanted some instances to run from Monday to Friday, and to start at 7am and stop at 5pm. Feedback collected from preview users as well as long-time Boto users has been our guidepost along the development process, and we are excited to bring this new stable version to our Python customers. resource('ec2') for instance in ec2. The following table you an overview of the services and associated classes that Boto3 supports, along with a link for finding additional information. The following are code examples for showing how to use boto3. import boto3. Adjust the region name as required. Finally, we’ll use the EC2 resource to get all of the instances and then print their instance ID and state. client('s3') # for client interface The above lines of code creates a default session using the credentials stored in the credentials file, and returns the session object which is stored under variables s3 and s3_client. 'i-1234567', return the instance 'Name' from the name tag. Here's what the script looks like:. That will be the URL you will use to SSH into the server. EC2, VPC, EBS, RDS, CloudFormation, CloudWatch, ELB, Auto-scaling. boto3 quick hands-on. Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. ec2 or s3). If you package Jython scripts and boto3 library inside a jar and then using Java's scripting API try to execute your code then you will get the exception shown below. We use cookies for various purposes including analytics. Thanks for looking into, ok so I guess that actually doing a string comparison against a dictionary item is ok. One Boto3 is installed, it will provide direct access to AWS services like EC2. web系エンジニアの速記的備忘録。メモ書き故、中身については保証致しません。また実在している団体等とは一切関係あり. I hope that this simple example will be helpful for you. It makes requesting cloud computing resources as easy as either clicking a few buttons or making an API call. Session(profile_name='my_profile'). As a result, you may find cases in which an operation supported by the client isn't offered by the resource. region_name, endpoint_url, etc. The following are code examples for showing how to use boto3. You cannot link an EC2-Classic instance to more than one VPC at a time. However, the bad news is that it is quite difficult to follow. I would assume if you are having an issue with EC2 using boto3 related to SSL errors, you may see similar issues with other services, assuming it has to do something with the cert being used. This Lambda function will be written in Python using the Boto3 library. I am developing a simple python script to add rules to securitygroups, and I am wondering what is the difference between the two methods available within boto3: authorize_security_group_ingress(**k. EC2 instances don't have a concept of an "owner". AWS_SERVER_PUBLIC_KEY, settings. I was recently asked to update a single tag in all of our 800 hosts only if there was already another tag present. This is achieved through the below snippet. js, Java and Python. client('ec2') I use the resource to get information or take action on a specific item. tbh I have been going round in circles from initially using describe instances and having to deal with lots of nested loops to get nested dictionary items which is potentially more difficult to maintain for colleagues and then discovering the concept of filtering. For our first script, let’s list the instances we have running in EC2. client taken from open source projects. Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. import boto3 s3 = boto3. Managing EC2 and VPC: AWS with Python and Boto3 Series HI-SPEED DOWNLOAD Free 300 GB with Full DSL-Broadband Speed!. 前回は、boto3のresourceを使ってEC2インスタンスの情報を取り出しました。 nasrinjp1. Used Boto3 to automate, Auto scaling policy for automating auto-scaling groups, Elastic load balancers, and launch configurations. This is done in an endless loop with a 1 second sleep for each iteration. There is no way I was going to use the GUI to recover that many items. Perform help (boto3) ,It will show the package content with this package. boto3 quick hands-on. The code section has. terminate() #for terminating an ec2 instance. Hi everyone, I am trying to find from which boto3 version the sts assume_role has the policy_arns in parameters but couldn't. AWS - Using Python and Boto3 to get Information about Untagged EC2 resources AWS Python Boto Just a quick post on a Python script to scan through all your EC2 Instances in the Specified Region, and if there's no Tags associated to the resource, the script will print information out about the resources in question. We will teach you how you can set up your environment on. Once we cover the basics, we'll dive into some more advanced use cases to really uncover the power of Lambda. client('ec2', region_name='us-west-2') resource = boto3. resource('ec2') ec2client = boto3. AWS has a concept of resource tags. Boto3 is Amazon's officially supported AWS SDK for Python. To get you started with Boto3 I have given an example below that shows how to create a key pair and launch an instance using Python script. We use cookies for various purposes including analytics. 我想允许用户仅在需要时启动EC2实例. Category People & Blogs. Posts about Boto3 written by lanerjo. By design, boto3 library can deploy EC2 instances in groups. resource(service_name='ec2') Let's use ec2. which investigates your AWS account and deletes the resources which are costing you money. boto3 quick hands-on. By default, resources within a VPC are not accessible from within a Lambda function. ここからが本題です。 実際にboto3を使ってEC2インスタンスを立ち上げ、立ち上げたインスタンスのPublicIPを取得してみる。. In this example we want to filter a particular VPC by the "Name" tag with the value of 'webapp01'. EC2 instances don't have a concept of an "owner". The basic items we need to create are as follows: Lambda function to get the total number of EC2 instances running in our account. So here's how I did it via script with Boto3. DataNotFoundError: Unable to load data for. Now we will launch an EC2 instance in the public subnet using CLI. So, our statement to get the resource service client is: This gives list of available EC2 services. I needed to figure out a way to start/stop instances automatically during certain periods. In this demo we are going to install Apache webserver with PHP and MySQL support on your Amazon Linux instance (L=Linux,A=Apache,M=MySQL,P=PHP or LAMP stack). Domain (string) --Indicates whether this Elastic IP address is for use with instances in EC2-Classic (standard) or instances in a VPC (vpc). Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. client('ec2') ec2_regions = [region['RegionName'] for region in client. They could also be your own services running on your own EC2 instances. Boto3 tutorial: create a vpc, a security group, a subnet, an instance on that subnet, then make that instance 'pingable' from Internet - boto3_tutorial. Note that you need to have permissions for EC2 and Cloudformation in order to create a stack with an EC2 instance, as well as iam permissions like iam:PassRole to give s3-read-permissions to the. amazon-ec2 - 在AWS中,只有一个实例处于“运行”状态才会收取一小时的使用费吗? amazon-ec2 - AWS EC2实例本地ip更改的解决方案; python - 坚持亚马逊ec2实例的状态检查; amazon-ec2 - AWS EC2中的预留实例是否比按需实例或竞价型实例具有更好的性能?. For our first script, let’s list the instances we have running in EC2. Boto is python sdk in amazon, which can be used for automation purpose for ec2,s3 etc. Cloudformation and/or boto3 Hello, We are running into a situation in the department where we are trying to decide what strategy to pursue when deploying resources (such as EC2 servers, VPCs, RDS, etc. EC2用のIAMロール「Role-B」を作成しSTSのAssumeRoleでアカウントAで作成したIAMロール「Role-A」のARNを指定します 上記のIAMロールをboto3がインストール済みのEC2インスタンスにアタッチ. Vijay has 3 jobs listed on their profile. resource ('ec2', region_name = "ap-southeast-2"). According to the boto3 documentation, resource attributes are lazy-loaded, meaning that the first API call is made when the attribute is first accessed. In this course, you will journey with Seth Godin teaches you how to implement EC2 and VPC resources on AWS using Python API - Boto3! Implement your infrastructure with code. We are now ready to create the gateway. By voting up you can indicate which examples are most useful and appropriate. PublicIpv4Pool (string) --The ID of an address pool. Launching an EC2 instance. setLevel(logging. Comparing Client vs. 1) You should remove "return instances", because keyword "return" may be used only in functions to return function's result. You can vote up the examples you like or vote down the ones you don't like. For example, you can start an Amazon EC2 instance and use a waiter to wait until it reaches the 'running' state, or you can create a new Amazon DynamoDB table and wait until it is available to use. We will use boto3 waiters in other parts of the code. setup_default_session(). A role specifies a set of permissions that you can use to access AWS resources. To help you manage your instances, images, and other Amazon EC2 resources, you can optionally assign your own metadata to each resource in the form of tags. resource ('sqs') s3 = boto3. For our first script, let’s list the instances we have running in EC2. Boto3 Question and For Loops Hi, I know there is a very easy way to do this in bash, but I can't figure out how to do it in Python. client('ec2') ec2 = boto3. To create an isolated Python environment for an Amazon EC2 instance running Amazon Linux, you need to: 1. Package the CloudFormation template. Go to the EC2 Launch wizard and copy the AMI that you want to resource from AWS arsenal. import boto3 ec2 = boto3. , dev/test environments). They're like that roommate freshman year that has never lived on their own. So if 26 weeks out of the last 52 had non-zero issues or PR events and the rest had zero, the score would be 50%. Overview In this post, we'll cover how to automate EBS snapshots for your AWS infrastructure using Lambda and CloudWatch. We'll be using the AWS SDK for Python, better known as Boto3. If you've used Boto3 to query AWS resources, you may have run into limits on how many resources a query to the specified AWS API will return (generally 50 or 100 results), although S3 will return up to 1000 results. EBS volumes created and attached to an instance at launch are deleted when that instance is terminated. (DEV307) Introduction to Version 3 of the AWS SDK for Python (Boto) | AWS re:Invent 2014 1. By voting up you can indicate which examples are most useful and appropriate. web系エンジニアの速記的備忘録。メモ書き故、中身については保証致しません。また実在している団体等とは一切関係あり. If the awscli test of the Simple Notification Service worked for you, here’s its equivalent in Python, which you can run as a script or interactively in iPython:. The function returns a VPC resource object. Configuring Run Command. If you've used Boto3 to query AWS resources, you may have run into limits on how many resources a query to the specified AWS API will return, generally 50 or 100 results, although S3 will return up to 1000 results. I only mention this because I'm trying to find how to list the MAC Address of a given Instance with an instance-id and this result showed up in search. By voting up you can indicate which examples are most useful and appropriate. readthedocs. To learn more about reading and writing data, see Working with Items in DynamoDB. I demonstrate how to automate the operational management tasks to AMI image backup creation for EC2 instances and subsequent clean up of those backup images using scheduled cron jobs on either a dedicated server or using AWS Lambda. Tagging Your Amazon EC2 Resources. The breadcrumbs to follow are EC2 tab > INSTANCES > Instances. Overview In this post, we'll cover how to automate EBS snapshots for your AWS infrastructure using Lambda and CloudWatch. Display the root device name of the machine to back up. Boto3 is the Python SDK for AWS, and is an incredibly useful tool for working AWS resources, and automating processes on the your Account. Usually the boto3 API has separate calls for tagging and untagging a resource. It allows developers to write software that makes use of Amazon services like S3 and EC2. 25 September 2017 on aws, leader-election, python, ec2 An introduction to the Leader Election problem The Leader Election is a classic distributed systems problem in which one node within a cluster has to be solely in charge of executing certain tasks. You can vote up the examples you like or vote down the ones you don't like. First thing's first let's import the boto3 library in Python create an 'ec2' resource object using the method 'resource()' after that using the create_vpc() method create a virtual private network by passing the CIDR notation as an argument to named parameter 'CidrBlock'. So here's how I did it via script with Boto3. The following table you an overview of the services and associated classes that Boto3 supports, along with a link for finding additional information. This is achieved through the below snippet. Thats all there is to getting Boto3. Moto - Mock AWS Services. Python: Demystifying AWS' Boto3 August 31, 2017 September 24, 2018 / Will Robinson As the GitHub page says, "Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. Filtering VPCs by tags. View Vijay G. terminate() #for terminating an ec2 instance. PACKAGE CONTENTS compat docs (package) dynamodb (package) ec2 (package) exceptions resources (package) s3 (package) session utils. import boto3 import logging #setup simple logging for INFO logger = logging. Below is the code which I have so far. On boto I used to specify my credentials when connecting to S3 in such a way: import boto from boto. This post will be updated frequently when as I learn more about how to filter AWS resources using Boto3 library. Adjust the region name as required. See the complete profile on LinkedIn and discover Vijay’s connections. #pipenv install -d ipython. An instance is automatically unlinked from a VPC when it's stopped - you can link it to the VPC again when. This is achieved through the below snippet. 0 Tutorial for Beginners 10 - Breast Cancer Detection Using CNN in Python" https://www. In the last blog post, we have discussed how to install Python Boto3 SDK for AWS. Here are the examples of the python api boto3. We'll build a solution that creates nightly snapshots for volumes attached to EC2 instances and deletes any snapshots older than 10 days. Click on EBS ID (volume ID), which will take you to the volume section under the EC2 dashboard. region = 'us-east-2' ec2 = boto3. while creating ec2. You can find the latest, most up to date, documentation at Read the Docs , including a list of services that are supported. sim ultaneously b y sharing the resources among them; the h yp ervisor b elo w the OS allows multiple OSs to share the real ph ysical hardw are and run concurrently. import boto3 import logging #setup simple logging for INFO logger = Find Study Resources Main Menu. These can conceptually be split up into identifiers, attributes, actions, references, sub-resources, and collections. This Lambda function will be written in Python using the Boto3 library. The only rule I learned in a year of using the AWS API is to look in both places, and create both a client and a resource. Show you how things work and how to get things done 3. - ec2_info_retriever. One of the main goals for a DevOps professional is automation. 参考: https://aws. Feedback collected from preview users as well as long-time Boto users has been our guidepost along the development process, and we are excited to bring this new stable version to our Python customers. resource ('s3') Every resource instance has a number of attributes and methods. To create an isolated Python environment for an Amazon EC2 instance running Amazon Linux, you need to: 1. How to configure python boto3 SDK for AWS. In this practical video, we will write a Lambda Function in PYTHON which investigates your AWS account and deletes the resources which are costing you money. txt" # filename on S3 destFileName="s3_abc. Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. Paginating S3 objects using boto3. Using boto3 with Jython from inside a JAR. With this plugin, if Jenkins notices that your build cluster is overloaded, it'll start instances using the EC2 API and automatically connect them as Jenkins agents. Aug 1, 2017 to install two Python libraries: boto3; the details about file upload, you can read a comprehensive. Both terminating and stopping has same code just change the method used. The function returns a VPC resource object. we will use python 3+, flask micro-framework and boto3 libs. 25 September 2017 on aws, leader-election, python, ec2 An introduction to the Leader Election problem The Leader Election is a classic distributed systems problem in which one node within a cluster has to be solely in charge of executing certain tasks. A principal (person or application) assumes a role to receive temporary permissions to carry out required tasks and interact with AWS resources. Boto3 has waiters for both client and resource APIs. When we're done, we will be able to log in to the new EC2 instance via SSH. Here step by a step python code to create IAM role. が、EC2インスタンスの起動停止は、boto3. client('cloudwatch') def lambda_handler(event, context): # Use the filter() method of the instances. OK, I Understand. 7 4) Role: Choose Existing Role 5) Existing Role: Select the Role created the in last step 5) Click Create Function Copy the below Python Code to the editor and save it-----import boto3. terminate_instances Particle State EC2 Instance State. Thats all there is to getting Boto3. AWS have a tool called EC2 Scheduler that gives you very flexible control over starting and stopping EC2 instances. " The good news is that Boto 3 is extremely well documented. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. By voting up you can indicate which examples are most useful and appropriate. It makes requesting cloud computing resources as easy as either clicking a few buttons or making an API call. Posted on May 1, 2018 Categories aws Tags amazon-ec2, amazon-vpc, amazon-web-services, aws-vpc, boto3 AWS Running Instance Throttling Due To Low CPU Credit I have a process running on an AWS EC2 micro instance. In this blog post, we will discuss how to create a LAMP stack in AWS using Python Boto3. Let’s get started with some basic scripts that work with EC2, S3, and RDS. 'i-1234567', return the instance 'Name' from the name tag. client taken from open source projects. New ec2-make-ami. The following are code examples for showing how to use boto3. It can be used side-by-side with Boto in the same project, so it is easy to start using Boto3 in your existing projects as well as new projects. In previous section we initialized our EC2 resource using boto3 module which acts as a proxy to default session # Get EC2 resource ec2 = boto3. which investigates your AWS account and deletes the resources which are costing you money. resource('s3') Because default session is limit to the profile or instance profile used, sometime you need to use the custom session to override the default session configuration (e. I think of it as being at a ‘higher’ level than the client. outfile = open('ec2-keypair. Python: Demystifying AWS’ Boto3 August 31, 2017 September 24, 2018 / Will Robinson As the GitHub page says, “Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. CIDR notations are compact representations of the IP. resource('ec2') ec2instance = ec2. 0 Tutorial for Beginners 10 - Breast Cancer Detection Using CNN in Python" https://www. Boto3 has waiters for both client and resource APIs. Boto3's release notes. Adjust the region name as required. This R package provides raw access to the 'Amazon Web Services' ('AWS') 'SDK' via the 'boto3' Python module and some convenient helper functions (currently for S3 and KMS) and workarounds, eg taking care of spawning new resources in forked R processes. client('cloudwatch') def lambda_handler(event, context): # Use the filter() method of the instances. Click on EBS ID (volume ID), which will take you to the volume section under the EC2 dashboard. Doing this manually is an overhead and if you have multiple servers, this will be cumbersome. aws ec2 describe-instancesライクに参照したい。 ハマりポイントまでご一緒にお付き合いください。. As the GitHub page says, “Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like Amazon S3 and Amazon EC2. Here are 2 sample functions to illustrate how you can get information about Tags on instances using Boto3 in AWS. A basic boto3 based tool for retrieving information from running EC2 instances. tbh I have been going round in circles from initially using describe instances and having to deal with lots of nested loops to get nested dictionary items which is potentially more difficult to maintain for colleagues and then discovering the concept of filtering. It is common practice in Ansible AWS modules to have a purge_tags parameter that defaults to true. I think of it as being at a ‘higher’ level than the client. See: SSM Run Command Walkthrough Using the AWS CLI. resource(‘ec2’), but my biggest difficulty is to referring and extracting the data from ec2client or ec2 objects. resource('ec2') def lambda_handler(event, context): # Use the filter() method of the instances collection to retrieve # all running EC2 instances. While similar, their implementations vary, and this comparison points out use cases to consider for both. In the last blog post, we have discussed how to install Python Boto3 SDK for AWS. A simple way to achieve this is to use an Amazon CloudWatch Events rule to trigger an AWS Lambda function daily. Clients: return description objects and appear lower level. name This will print the names of all th e buckets in your S3. Session(profile_name='my_profile'). It seems Boto3 has two types of interfaces, clients and resources. If you package Jython scripts and boto3 library inside a jar and then using Java's scripting API try to execute your code then you will get the exception shown below. Boto3 is Amazon’s officially supported AWS SDK for Python. Amazon web services (AWS) is a useful tool to alleviates the pain of maintaining infrastructure. Resources: Add Amazon EC2 support for ClassicLink actions and add a delete action to EC2 Volume resources. There is no way I was going to use the GUI to recover that many items. Note that you need to have permissions for EC2 and Cloudformation in order to create a stack with an EC2 instance, as well as iam permissions like iam:PassRole to give s3-read-permissions to the. Some resources can be used in all regions (global), and some resources are specific to the region or Availability Zone in which they reside. I demonstrate how to automate the operational management tasks to AMI image backup creation for EC2 instances and subsequent clean up of those backup images using scheduled cron jobs on either a dedicated server or using AWS Lambda. resource Mocking boto3 S3 client method Python python mock boto3 client (4) I'm trying to mock a singluar method from the boto3 s3 client object to throw and exception. So you have two options: Option 1: Scan through CloudTrail looking for the log entry that created the EC2 instance. You can find the latest, most up to date, documentation at Read the Docs , including a list of services that are supported. I want to create an Ec2 instance using Python boto3? Can anyone help me with the code. setup_default_session(). resource('ec2') ec2instance = ec2. Now we have list of EC2 services, return by boto3's "resource" function. { "AWSTemplateFormatVersion": "2010-09-09", "Description": "(SO0011) - Cost Optiminzation EC2 Right Sizing - AWS CloudFormation Template for AWS Solutions Builder.