Is it possible to create an ec2 instance using boto3 in python? Boto3 document is not helping here, and I couldn't find any helping documents online. please provide some sample codes/links.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
The API has changed but it's right there in the documentation
Link to the documentation: http://boto3.readthedocs.org/en/latest/guide/migrationec2.html#launching-new-instances
The link you're really looking for in the documentation is the
create_instances()
method of the ServiceResource object. This is the type of object you are calling if you create an EC2 resource like this:This contains a more detailed example and a longer list of available parameters.
You can also get parameter values for AWS instances that are already running using the AWS command line interface:
This prints out a JSON file from which relevant parameters can be extracted and passed to the
create_instances()
method. (Or, you can use a boto client and call thedescribe_instances()
method.)(Note: If you're wondering what the difference is between the Client and the Resource, they serve different purposes for the same end - the client is a lower-level interface while the Resource is a higher-level interface.)
If your running from your windows computer you need configure AWS Cli with proper EC2 permisssion to launch instance.
#Refer to API docs has all available options to create instance
http://boto3.readthedocs.org/en/latest/reference/services/ec2.html#EC2.Subnet.create_instances
You can run the code I used from the boto3 docs. You can add or remove parameters as per your requirements, but this is what you would normally require: