How Do You Pass Two or More Subnets to an “aws eks” Command?

Problem scenario
You want to pass more than one subnet to an "aws eks" command.

You tried to delimit the list with commas (or separate two subnet IDs with commas). You received this error message:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The subnet ID 'subnet-0abcd1234,subnet-zyxw9876' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidSubnetID.NotFound; Request ID: Proxy: null)

What should you do?

Solution
Separate the subnet IDs with a space. Here is an example of the correct syntax:

aws eks create-nodegroup --cluster-name coolname --nodegroup-name "variousmachines" --subnets subnet-0abcd1234 subnet-zyxw9876 --node-role arn:aws:iam::<removed>:role/nameofroll --remote-access ec2SshKey=pairname,sourceSecurityGroups=sg-0securitygroup1,sg-0securitygroup2

# It is worth noting that the security groups are passed with commas and no spaces.
# But subnets are passed with spaces and no commas
# If you want to see what security groups you can choose from, run this command:
# aws eks describe-cluster --name contint --query 'cluster.resourcesVpcConfig.securityGroupIds'
# If you want to see what subnets you can choose from, run this command:
# aws eks describe-cluster --name foo --query 'cluster.resourcesVpcConfig.subnetIds'
# If you can remember a pattern in the name of the relevant role (i.e., "foobar"), try a command like this to find the exact IAM role:
# aws iam list-roles | grep -i foobar

Leave a comment

Your email address will not be published. Required fields are marked *