I am trying to create an EC2 instance (Amazon Linux, so I shouldn't have to configure the SSM agent as it should be autoconfigured) in a private subnet, and want to be able to SSH into it. According to this post I have to use AWS Systems Manager for this. I've done quite a bit with codestar/beanstalk before, but now simply want to be able to create and delete everything via the AWS CLI manually for learning purposes.
Here are the commands I'm able to run fine (the ec2 instance is created succesfully with my role)
aws iam create-role --role-name ec2-role --assume-role-policy-document file://roles/ec2-role.json
aws iam attach-role-policy --role-name ec2-role --policy-arn "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
aws iam create-instance-profile --instance-profile-name ssm-instance-profile-for-ec2-instances
aws iam add-role-to-instance-profile --instance-profile-name ssm-instance-profile-for-ec2-instances --role-name ec2-role
// Creating the EC2 instance
aws ec2 run-instances --image-id ami-0db9040eb3ab74509 --count 1 --instance-type t2.micro --key-name key-pair-for-instance1 --subnet-id <my_valid_subnet_id> --iam-instance-profile Name=ssm-instance-profile-for-ec2-instances
I took parts of these commands from this post.
My json file for ec2-role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
]
}
Unfortunately this instance isn't visible in the SSM (Systems Manager):
aws ssm describe-instance-information
{
"InstanceInformationList": []
}
I have been following the main documentation on SSM and from what I understand from the page below is that all you would need is the AmazonSSMManagedInstanceCore policy: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-instance-profile.html
The web console hasn't been any help so far, according to this page it treats roles and instance-profiles as the same thing.
What am I missing here to be able to use the aws ssm command to start an ssh session?