
IAM Role을 생성한 후 EC2에 연결해야 하는 경우가 있다. 그러나 Role을 생성한 뒤 EC2의 IAM 설정을 수정하려고 하면 “IAM 역할 없음”이라는 메시지가 출력될 수 있다. 이는 여러 가지 원인으로 발생할 수 있지만, 현재 상황에서는 Instance Profile이 생성되지 않았기 때문에 IAM 역할이 나오지 않는 것으로 확인이 되었다.
일반적으로 EC2를 위한 IAM Role을 생성하면 Instance Profile이 자동으로 생성된다. 또한, 신뢰 관계(Trust Policy)에 ec2.amazonaws.com만 지정된 경우에도 Instance Profile이 자동으로 생성되는 것을 확인하였다. 하지만 아래 JSON과 같이, 필자가 추가하려는 Role의 신뢰 관계에는 EC2 외에도 여러 서비스가 포함되어 있어 Instance Profile이 자동으로 생성되지 않았다. 이로 인해 EC2에 해당 IAM Role을 지정할 수 없는 상황이 발생했다. 따라서, 이러한 경우 수동으로 Instance Profile을 생성하고 신규 생성한 Role을 연결하는 방법을 알아보는 시간을 가져보려고 한다.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com",
"codepipeline.amazonaws.com",
"codebuild.amazonaws.com",
"ecs-tasks.amazonaws.com",
"codedeploy.amazonaws.com",
"application-autoscaling.amazonaws.com",
"cloudwatch.amazonaws.com",
"events.amazonaws.com",
"codecommit.amazonaws.com",
"ecs.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
✅ 01. 인스턴스 프로파일 생성 및 역할 연결
01-1. Instance Profile란?
Instance Profile란 EC2 인스턴스가 특정 IAM 역할(Role)을 사용할 수 있도록 하는 컨테이너 역할을 수행한다. EC2 인스턴스는 Instance Profile을 통해 임시 자격 증명(Temporary Security Credentials)을 획득하여 안전하게 AWS 서비스에 접근이 가능하다. 또한, Instance Profile은 EC2를 위한 서비스라 봐도 무방하다.
Instance Profile은 EC2를 위한 컨테이너 역할을 수행하는 서비스이고, 임시 자격 증명을 통해 AWS 서비스에 접근을 하게 해준다. 그렇다면 이제 실제 Instance Profile을 AWS CLI 기반으로 생성하고, EC2에 신규 생성한 역할을 연결 해보자.
01-2. 인스턴스 프로파일 목록 확인
aws iam list-instance-profiles
{
"InstanceProfiles": []
}
위 CLI를 실행하면 현재 Instance Profile 목록 확인이 가능하며, 현재는 빈 값으로 출력되는 것을 확인할 수 있다. 그럼 빈 값으로 지정이 되어있으니 instance profile을 생성 해야한다.
01-3. 인스턴스 프로파일 생성
aws iam create-instance-profile --instance-profile-name testRoleInstanceProfile
{
"InstanceProfile": {
"Path": "/",
"InstanceProfileName": "testRoleInstanceProfile",
"InstanceProfileId": "Axxxxxxxxxxx",
"Arn": "arn:aws:iam::8xxxxxxxxxxx:instance-profile/testRoleInstanceProfile",
"CreateDate": "2025-03-13T11:37:13+00:00",
"Roles": []
}
}
위 CLI를 실행하면 다음과 같은 정보가 출력된다. 자세한 내용은 아래에 기재되어 있으며, 이제 이전에 생성한 역할(Role)을 내가 만든 Instance Profile에 연결해보자.
- Path: IAM Instance Profile의 경로, 기본값이 "/"이며 조직 내의 IAM 리소스 분류 시 다른 경우 사용 가능
- InstanceProfileName: Instance Profile 이름
- InstanceProfileId: Instance Profile 고유 ID
- Arn: Instance Profile ARN
- CreateDate: 생성일
- Roles: 연결되어 있는 역할(Role) 목록
aws iam add-role-to-instance-profile --instance-profile-name <위에서 만든 Instance Profile 이름> --role-name <내가 만든 IAM Role 이름>
위 command를 통해, 이전에 생성한 역할(Role)을 위에서 만든 Instance Profile에 연결하는 작업을 진행한다. 위와 같이 연결하면 콘솔 창(EC2 > 인스턴스 > Instance ID > IAM 역할 수정)에서는 내가 생성한 역할(Role)이 아래 이미지와 같이 표시되는 것을 확인할 수 있다. 목록에 IAM Role이 표시되었으니 IAM 역할 업데이트를 클릭 하자.

IAM 역할 업데이트를 클릭 하였는데, 아래와 같은 오류가 출력이 된다.
인스턴스 프로파일에 대한 attach 실패
You are not authorized to perform this operation. User: arn:aws:sts::8xxxxxxxx:assumed-role/search-xxxxxxxx-dev-role/ymkim1085@xxx.xxx is not authorized to perform: iam:PassRole on resource: arn:aws:iam::8xxxxxxxx:role/xxxx-xxxx-role because no identity-based policy allows the iam:PassRole action. Encoded authorization failure.....
위 오류는 iam:PassRole 권한 부족으로 발생한 문제다. EC2에 Role을 Attach 하는 행위 자체가 어떻게 보면 “해당 Role을 EC2 서비스에 넘겨주는(Pass) 것으로 간주해야 한다. 그렇기에 주체(로그인한 콘솔 사용자)에게 PassRole이 없으면 권한 오류가 발생한다.
01-4. 역할 전환한 역할에 PassRole 추가
필자의 경우 A account 로그인 후 test-dev-role이라는 역할(Role)로 역할 전환을 수행한 상태다. 그렇기에 test-dev-role 역할에 EC2에 Attachment할 역할을 Passrole 할 수 있는 Custom 정책을 신규 생성할 것이다. 우선 해당 역할에 아래와 같은 인라인 정책을 추가한다. 후에 다시 한번 EC2에 IAM Role을 추가해보자.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": [
"iam:PassRole"
],
"Resource": [
"arn:aws:iam::8xxxxxxxx:role/<본인이 만든 역할 이름>"
]
}
]
}

PassRole 권한을 추가한 뒤 EC2에 IAM Role을 연결하면 정상적으로 역할이 적용된다. 다만, 해당 IAM Role에 ec2.amazonaws.com이 포함된 신뢰 관계를 설정하고, Instance Profile을 생성한 후 PassRole까지 지정해야 EC2에서 이 역할을 제대로 사용할 수 있을 것이다.
99. 참고 자료
How to Create an EC2 Instance Profile with the AWS CLI
Introduction
medium.com
My IAM role is not listed when trying to create a new EC2 instance
Hi there, I have created an AWS Active Directory and am now trying to create an EC2 Window Server 2012 to connect to the directory/domain. On the configure instance details, I can select the direct...
repost.aws
IAM Role does not show in role list of EC2, even though I have the trust relationship set up correctly
I have the following demo role created for AWS: with the following trust relationship: Now, I am trying to modify the role of an EC2 instance to be DemoRoleForEC2, but the role is not appearing i...
stackoverflow.com
'Public Cloud > AWS - Experience' 카테고리의 다른 글
[AWS] 가비아 도메인 구입 후 Route53을 통한 EC2 연결 방법 (0) | 2025.03.18 |
---|---|
[AWS] AWS CLI Profile(프로파일) 설정 방법? (0) | 2025.03.15 |
[AWS] ECS ASG 구성 시 ServiceLinkedRole 권한 이슈가 발생하는 경우? (0) | 2025.03.11 |
[AWS] IAM 그리고 AssumeRole vs PassRole란? (0) | 2025.03.11 |
[AWS] ECS 실행중인 Task에 Tag 지정(tag propagation)하기 (0) | 2025.03.10 |