how to create iam role for ec2 instance code example
Example 1: attach iam role to ec2 instance cli
$aws ec2 associate-iam-instance-profile --instance-id YourInstanceId --iam-instance-profile Name=YourNewRole-Instance-Profile
Example 2: how to keep name for ec2 instance running
sudo hostnamectl set-hostname webserver.localdomain
Example 3: ec2 instance info
AWS EC2 Instance Comparison