I\'m attempting to call run-instances and pass the resulting instance IDs as the input to create-tags as a one-liner as follows:
aws ec2 run-instances \\
It can be done by leveraging xargs {} to capture the instance IDs to feed it into the --resources parameter of create-tags.
aws ec2 run-instances \
--image-id ami-1234 \
--output text \
--query Instances[*].[InstanceId] | \
xargs -I {} aws ec2 create-tags \
--resources {} \
--tags 'Key="foo",Value="bar"'
Note that unlike the example in the original question, it's important to wrap the "InstanceId" portion of the --query parameter value in brackets so that if one calls run-instances with --count greater than one, the multiple instance IDs that get returned will be outputted as separate lines instead of being tab-delimited. See http://docs.aws.amazon.com/cli/latest/userguide/controlling-output.html#controlling-output-format