I'm trying to run in PowerShell the command that creates EC2 instance with 2 security groups "sg-01" and "sg-02":
aws ec2 run-instances --image-id $amiId --count 1 --instance-type 't3.micro' --key-name $keyPair --su.net-id 'su.net-01' --security-group-ids 'sg-01 sg02'
But I get the error: The parameter groupName cannot be used with the parameter su.net
. The problem is with the --security-group-ids parameter which is 'sg-01 sg-02'
. In all examples I can see only one security group used. In this SO question it's recommended to separate them with space. I tried the next variants:
--security-group-ids sg-01,sg02
--security-group-ids 'sg-01,sg02'
--security-group-ids sg-01 sg02
--security-group-ids 'sg-01 sg02'
But the error is the same. If I try with just one group --security-group-ids 'sg-01'
then the instance is created successfully.
I was confused by the run-instances documentation where the syntax is defined as "string" "string"...
. The next value helps to create an instance with two security groups:
--security-group-ids @('sg-01','sg-02')
I'm using PowerShell and elshev's solution worked for me.
$SGids = @('sg-01','sg-02')
--security-group-ids $SGids
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.