Complete the code to specify the Amazon Machine Image (AMI) ID when launching an EC2 instance.
ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='[1]', MinCount=1, MaxCount=1, InstanceType='t2.micro')
The ImageId parameter requires the AMI ID, which looks like ami-0abcdef1234567890. This tells AWS which image to use for the instance.
Complete the code to specify the instance type when launching an EC2 instance.
ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='ami-0abcdef1234567890', MinCount=1, MaxCount=1, InstanceType='[1]')
The InstanceType parameter defines the size and power of the instance. t2.micro is a common small instance type.
Fix the error in the code by filling the correct parameter name for the key pair when launching an EC2 instance.
ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='ami-0abcdef1234567890', MinCount=1, MaxCount=1, InstanceType='t2.micro', [1]='my-key-pair')
The correct parameter to specify the key pair name is KeyName. This allows you to connect to the instance securely.
Fill both blanks to add a security group and a tag to the EC2 instance.
ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='ami-0abcdef1234567890', MinCount=1, MaxCount=1, InstanceType='t2.micro', SecurityGroupIds=['[1]'], TagSpecifications=[{'ResourceType': 'instance', 'Tags': [{'Key': 'Name', 'Value': '[2]'}]}])
The SecurityGroupIds parameter expects a list of security group IDs like sg-12345678. The tag Name is set to a friendly name like MyInstance.
Fill all three blanks to create an EC2 instance with a specific subnet, assign a public IP, and add a tag.
ec2 = boto3.resource('ec2') instance = ec2.create_instances(ImageId='ami-0abcdef1234567890', MinCount=1, MaxCount=1, InstanceType='t2.micro', NetworkInterfaces=[{'SubnetId': '[1]', 'DeviceIndex': 0, 'AssociatePublicIpAddress': [2]], TagSpecifications=[{'ResourceType': 'instance', 'Tags': [{'Key': 'Name', 'Value': '[3]'}]}])
The SubnetId specifies the subnet like subnet-1a2b3c4d. AssociatePublicIpAddress is a boolean to assign a public IP, here True. The tag Name is set to WebServer.