# variables.py
role_config = {
"lambda": {
"trusted_role_services": ["lambda.amazonaws.com"],
"custom_role_policy_arns": ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"]
},
"ec2": {
"trusted_role_services": ["ec2.amazonaws.com"],
"custom_role_policy_arns": ["arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess"]
},
# 添加其他角色的配置
}
# main.py
from variables import role_config
from somewhere import IamAssumableRole # 假设IamAssumableRole是你定义的或者导入的类
for role_name, config in role_config.items():
IamAssumableRole(
self,
role_name,
trusted_role_services=config["trusted_role_services"],
create_role=True,
role_name=role_name,
custom_role_policy_arns=config["custom_role_policy_arns"]
)