Hi@akhtar,
You can use a network interface in your EC2 instance. It will allow you to use a subnet in a VPC as shown below.
# Create a linux instance in the subnet
instances = ec2.create_instances(
ImageId='ami-0de53d8956e8dcf80',
InstanceType='t2.micro',
MaxCount=1,
MinCount=1,
NetworkInterfaces=[{
'SubnetId': subnet.id,
'DeviceIndex': 0,
'AssociatePublicIpAddress': True,
'Groups': [securitygroup.group_id]
}],
KeyName='ec2-keypair')