IamInstanceProfile: The name of the IAM profile that will be attached to the EC2 instance.SecurityGroupIds: Security groups allow you to control access into and out of your EC2 instance.If no KeyName is specified, we won’t be able to SSH into the EC2 instance. KeyName: The name of the key pair that will be used to access the EC2 instance.Information about all the instance types is available here. InstanceType: The instance type for the EC2 instance.MaxCount: Maximum number of EC2 instances to create.MinCount: Minimum number of EC2 instances to create.For this tutorial, we will use the Amazon Linux 2 AMI in us-west-2. You can either use one of the freely available AMIs provided by Amazon or create your own. ImageId: An Amazon Machine Image (AMI) is required to launch an EC2 instance. How to create a new EC2 instance using Boto3? Requirements for creating an EC2 instance The function above creates an EC2 key pair with the name ec2-key-pair and then stores in a file located at /tmp/aws_ec2_key.pem with the 400 permissions that will be needed when we use the private key to access the EC2 instance. O_CREAT, 0o400 ), "w+" ) as handle : handle. create_key_pair ( KeyName = "ec2-key-pair" ) private_key = key_pair # write private key to file with 400 permissions client ( "ec2", region_name = "us-west-2" ) key_pair = ec2_client. Def create_key_pair (): ec2_client = boto3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |