Knife ec2 server create

Folks,

How to create EC2 instance in VPC using Knife?

I added aws access key and secret key in knife.rb .
I was running command as
knife ec2 server create –I ami-456b493a -S D:/Key/ec2.pem –f t2.small -x ubuntu –g sg-qwe2d4 -s subnet-12a456 -VV

For this I got ERROR as
ERROR: InvalidParameterCombination => VPC security groups may not be used for a non-VPC launch

This is my Knife.rb file

current_dir = File.dirname(__FILE__)
log_level                :info
log_location             STDOUT
node_name                "raju"
client_key               "#{current_dir}/raju.pem"
chef_server_url          "https://api.chef.io/organizations/NAME"
cookbook_path            ["#{current_dir}/../cookbooks"]

knife[:aws_access_key_id] = "********"
knife[:aws_secret_access_key] = "*************"

Was there any configuration mistake?
Do I need to open ports?

i am new to chef too, try to not use security group and see if that works. "remove '–g sg-qwe2d4'"

knife ec2 server create -r 'role[jasonwebserver]' -I ami-1853ac65 -f t2.micro --subnet subnet-a1208ace --ssh-key xxx123

is the VPC that you want to launch your instance in a default VPC or non-default vpc? Based on this article. https://stackoverflow.com/questions/22365470/launching-instance-vpc-security-groups-may-not-be-used-for-a-non-vpc-launch

As I understand, you may want to launch an instance in a default VPC (since you didn't define VPC name in your command), but the security groups may be attacked to non-default VPC. This may create problem, since security groups are VPC related.

image.png