I’m creating a simple bash script that launches an instance with User Data, creates an images, and then launches multiple instances using that image. The output keeps hanging just after creating the first Instance, waiting for user input to proceed.
amazonLinux2AMI="ami-08f3d892de259504d"
keypair="NV"
keypair2="NV2"
keypairOhio="ec2keypair"
userdata="assign8userdata.txt"
assign8SGid=$(aws ec2 create-security-group --group-name Assign8SG --description "Assignment#8 security group" --query 'GroupId' --output text)
echo "creating SG"
aws ec2 authorize-security-group-ingress --group-name Assign8SG --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 run-instances --image-id "$amazonLinux2AMI" --instance-type t2.nano
--key-name "$keypair" --associate-public-ip-address --user-data file://$userdata
--security-group-ids "$assign8SGid"
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Assignment8task1}]'
Instance1Id=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=Assignment8task1" --query Reservations[0].Instances[0].InstanceId --output text)
aws ec2 wait instance-running $Instance1Id
aws ec2 create-image --instance-id "$Instance1Id" --name "FirstImage" --description "An AMI for my server" --tag-specifications 'ResourceType=image,Tags=[{Key=Name,Value=FirstImage}]'
sleep 10
ImId=$(aws ec2 describe-images --filters "Name=tag:Name,Values=FirstImage" --query 'Images[*].[ImageId]' --output text);
aws ec2 wait image-available --image-ids $ImId
sleep 10s;
echo "New imageID is: $ImId";
aws ec2 run-instances --image-id "$ImId" --key-name "$keypair2" --instance-type t2.nano --associate-public-ip-address --security-group-ids "$assign8SGid" --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Assignment8task2}]';
output will stuck here waiting for an entry (proceeds after hitting keyboard entry)
"Return": true,
"SecurityGroupRules": [
{
"SecurityGroupRuleId": "sgr-0d66055fe7a010562",
"GroupId": "sg-024a4b34a994bb2e1",
"GroupOwnerId": "138033532330",
"IsEgress": false,
"IpProtocol": "tcp",
"FromPort": 80,
"ToPort": 80,
"CidrIpv4": "0.0.0.0/0"
}
]
}
{
"Groups": [],
"Instances": [
{
"AmiLaunchIndex": 0,
"ImageId": "ami-08f3d892de259504d",
"InstanceId": "i-077771dfb9a82c51e",
"InstanceType": "t2.nano",
"KeyName": "NV",
"LaunchTime": "2022-07-27T17:40:06+00:00",
"Monitoring": {
"State": "disabled"
},
"Placement": {
"AvailabilityZone": "us-east-1c",
"GroupName": "",
2
Answers
When results are longer than one screen, AWS CLI v2 uses a paginator.
To turn it off, put this in the
~/.aws/config
file:For details, see: Using AWS CLI pagination options – AWS Command Line Interface
In most cases you can pass
--no-cli-pager
to commands and prevent them from using the pager (which is by defaultless
on macos and I assume linux as well.If you want it to be a global settings, you can follow @john rotenstiens answer which is to set the cli_pager in the ~/.aws/config
So
--no-cli-pager
to your aws commandcli_pager=