IAM roles for EC2 instances allow the instances to make secure API requests to AWS services. You create a role with appropriate permissions and associate it with the EC2 instance during or after its creation.
Example:
aws ec2 associate-iam-instance-profile --instance-id i-1234567890abcdef0 --iam-instance-profile Name=MyInstanceProfile