티스토리 뷰
반응형
import boto3
import json
# IAM 역할을 생성하고 태그를 추가하는 함수
def create_role_and_add_tags(profile_name, role_name, trust_policy, tags):
# 세션 생성
session = boto3.Session(profile_name=profile_name)
iam_client = session.client('iam')
# IAM 역할 생성
print(f"Creating role {role_name} in profile {profile_name}...")
response = iam_client.create_role(
RoleName=role_name,
AssumeRolePolicyDocument=json.dumps(trust_policy)
)
print(f"Role creation response for profile {profile_name}: {response}")
# IAM 역할에 태그 추가
print(f"Adding tags to role {role_name} in profile {profile_name}...")
iam_client.tag_role(
RoleName=role_name,
Tags=tags
)
print(f"Tags added to role {role_name} for profile {profile_name}")
# 각 계정의 자격 증명을 위한 프로파일 리스트
profiles = ['fendys-prod','fendys-dev'] # AWS CLI 프로파일 이름
# 역할 생성에 사용할 신뢰 정책
trust_policy = {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
# 역할에 추가할 태그 리스트
tags = [
{'Key': 'fendys.com/ticket', 'Value': 'fendys-12345'}
]
# 각 계정에 대해 IAM 역할 생성 및 태그 추가
for profile in profiles:
role_name = f'saml-fendys-role'
create_role_and_add_tags(profile, role_name, trust_policy, tags)
반응형
'AWS' 카테고리의 다른 글
aws multi account attach iam role & policy python (boto3) (0) | 2024.09.02 |
---|---|
aws multi account create iam policy python (boto3) (0) | 2024.09.02 |
aws s3 bucket lifecycle set (0) | 2023.07.12 |
install on centos7 + docker +awx 17.1.0 (0) | 2022.06.02 |
IDC -> aws 실시간 sync (lsync) (0) | 2022.03.16 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- vm rac
- ISCSI 볼륨 RAC
- cisco ansible
- DL20 GEN9 장비에 CentOS 7
- CentOS 7 GUI
- ansible network
- ILO
- cgroup
- shell connmad log
- kernel 변경
- 특정 라인삭제
- cmd로 윈도우 계정 관리
- windows.old 강제삭제
- centos7 ntp
- 윈도우서버 계정 관려
- dl20 centos7
- cmd로 계정 생성
- ipmi
- chrony
- 특정 문구 치환
- ansible ios
- dl20 g9 centos7 설치
- 리눅스 커맨드 로그남기기
- nxos ansible
- dl20
- ios ansible
- 윈도우 cmd 계정 관리
- linux command log
- nutanix rac
- oracle linux8 kernel
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함