AWS EC2 User Data
User data means the launch script for your EC2. For example, you can create a User Data to download a website from git and put it to the web folder. So you do not need to do any setup by SSH after launch.
Another function is do some basic setup so we do not need to do it every time when we launch like update and install some common packages.
sudo apt update sudo apt -y upgrade sudo apt install -y unzip jq reboot
Amazon Linux 2
sudo yum update sudo yum install -y amazon-efs-utils jq
To update all packages on an Amazon Linux instance
(Optional) Start a screen session in your shell window. Sometimes you might experience a network interruption that can disconnect the SSH connection to your instance. If this happens during a long software update, it can leave the instance in a recoverable, although confused state. A screen session allows you to continue running the update even if your connection is interrupted, and you can reconnect to the session later without problems.
- Execute the screen command to begin the session.
- If your session is disconnected, log back into your instance and list the available screens.
17793.pts-0.ip-12-34-56-78 (Detached) 1 Socket in /var/run/screen/S-ec2-user.
- Reconnect to the screen using the screen -r command and the process ID from the previous command.
screen -r 17793
- When you are finished using screen, use the exit command to close the session.
[screen is terminating]