Bash- Running aws ec2 run-instances in background - bash

How can i run the command aws ec2 run-instances in bash (mac os) so it will run in the background? (Right now when i run it it is in interactive mode in which i need to scroll until the end)

That command actually executes and completes immediately.
However, the AWS CLI is using a pager to show you the output. You can modify this behaviour by either requesting less information to be returned by using --query, or by removing the pager.
To remove the pager, add this to your ~/.aws/config file:
[default]
cli_pager=
This will cause all output to scroll up the screen without waiting for user input.
For more details, see: Using AWS CLI pagination options - AWS Command Line Interface

Related

aws esc windows container pseudoTerminal cloudwatch ouput with strange chars

I am running AWS ESC (Windows EC2).
The container with -t runs well on my machine. The task definition has pseudoTerminal: true so that it will run -t on Windows EC2.
The output logged into CloudWatch log group has strange chars beside the correct data.
Note: the output is fine when running without -t (pseudoTerminal: null)
Looks like my container output using the xterm control sequences.
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Definitions

aws cli autoscaling command doesn't return to shell promot

In Macbook pro, iterm2 with aws cli, shell zsh.
When running below command, the shell goes to an empty screen with "(END)" on the top left corn. I have to press "q" to exit to get back to shell prompt.
aws autoscaling update-auto-scaling-group --auto-scaling-group-name xxx --desired-capacity 1
This is very annoying. How can I change it so that the command just return back to normal shell promot?
Not all aws cli command has this same behavior. Like "aws s3 ls" runs ok.
Thanks.
The AWS CLI v2 has the option to specify a pager to handle output that goes longer than one screen.
If you wish to display all output with no pagination, edit the ~.aws/config file and insert:
[default]
cli_pager=
See: AWS CLI version 2 uses a paging program for all output by default

AWS Launch Configuration not picking up user data

We are trying to build an an autoscaling group(lets say AS) configured with an elastic load balancer(lets say ELB) in AWS. The autoscaling group itself is configured with a launch configuration(lets say LC). As far as I could understand from the AWS documentation, pasting a script, as-is, in the user data section of the launch configuration would run that script for every instance launched into an auto scaling group associated with that auto scaling group.
For example pasting this in user data would have a file named configure available in the home folder of a t2 micro ubuntu image:
#!/bin/bash
cd
touch configure
Our end goal is:
Increase instances in auto scaling group, they launch with our startup script and this new instance gets added behind the load balancer tagged with the auto scaling group. But the script was not executed at the instance launch. My questions are:
1. Am i missing something here?
2. What should I do to run our startup script at time of launching any new instance in an auto scaling group?
3. Is there any way to verify if user data was really picked up by the launch?
The direction you are following is right. What is wrong is your user data script.
Problem 1:
What you have to remember is that user data will be executed as user root, not ubuntu. So if your script worked fine, you would find your file in /root/configure, NOT IN /home/ubuntu/configure.
Problem 2:
Your script is actually executing, but it's incorrect and is failing at cd command, thus file is not created.
cd builtin command without any directory given will try to do cd $HOME, however $HOME is NOT SET during cloud-init run, so you have to be explicit here.
Change your script to below and it will work:
#!/bin/bash
cd /root
touch configure
You can also debug issues with your user-data script by inspecting /var/log/cloud-init.log log file, in particular checking for errors in it: grep -i error /var/log/cloud-init.log
Hope it helps!

How can I interact with a Vagrant shell provisioning script?

I have a shell provisioning script that invokes a command that requires user input - but when I run vagrant provision, the process hangs at that point in the script, as the command is waiting for my input, but there is nowhere to give it. Is there any way around this - i.e. to force the script to run in some interactive mode?
The specifics are that I creating a clean Ubuntu VM, and then invoking the Heroku CLI to download a database backup (this is in my provisioning script):
curl -o /tmp/db.backup `heroku pgbackups:url -a myapp`
However, because this is a clean VM, and therefore this is the first time that I have run an Heroku CLI command, I am prompted for my login credentials. Because the script is being managed by Vagrant, there is no interactive shell attached, and so the script just hangs there.
If you want to pass temporary input or variables to a Vagrant script, you can have them enter their credentials as temporary environment variables for that command by placing them first on the same line:
username=x password=x vagrant provision
and access them from within Vagrantfile as
$u = ENV['username']
$p = ENV['password']
Then you can pass them as an argument to your bash script:
config.vm.provision "shell" do |s|
s.inline: "echo username: $1, password: $2"
s.args: [$u, $p]
end
You can install something like expect in the vm to handle passing those variables to the curl command.
I'm assuming you don't want to hard code your credentials in plain text thus trying to force an interactive mode.
Thing is just as you I don't see such option in vagrant provision doc ( http://docs.vagrantup.com/v1/docs/provisioners/shell.html ) so one way or another you need to embed the authentication within your script.
Have you thought about using something like getting a token and use the heroku REST Api instead of the CLI?
https://devcenter.heroku.com/articles/authentication

Describing E2C instance doesn't return anything

I've started an EC2 instance and installed the ec2-api-tools. Environment variables (JAVA_HOME, EC2_PRIVATE_KEY, EC2_CERT) are set up.
Running ec2-describe-instances doesn't return anything. According to the EC2 command line reference information on all currently running (and terminated) instances should be returned. What's going wrong?
In general ec2-describe-images -o self -o amazon works, so the EC2 tools are working. Adding explicitly -K and -C parameters to ec2-describe-instances doesn't change the situation.
A little more detail:
You don't need to set the EC2_URL directly. You can use the more friendly command-line option:
--region eu-west-1
(substituting the name of the region you want to address).
This way you don't need to look up the region's URL endpoint.
Here are the EC2 Command Line API Tools general options where this is explained.
if all your instances are in eu-west-1, configure your aws cli to use this region by default.
just type : aws configure
and you ll be prompted to enter your credential, then you can rewrite the region

Resources