此问题出现是因为缺少IAM角色。需要创建一个IAM角色并将其附加到Redshift集群上。下面是一个Python代码示例,用于创建IAM角色并将其附加到Redshift集群上:
import boto3
# Create an AWS IAM client
iam = boto3.client('iam')
# Create the IAM role
iam.create_role(
RoleName='RedshiftRole',
AssumeRolePolicyDocument={
'Statement': [{
'Action': 'sts:AssumeRole',
'Effect': 'Allow',
'Principal': {
'Service': 'redshift.amazonaws.com'
}
}],
'Version': '2012-10-17'
}
)
# Attach the IAM role to the Redshift cluster
redshift = boto3.client('redshift')
redshift.modify_cluster_iam_roles(
ClusterIdentifier='my-redshift-cluster',
AddIamRoles=[
'arn:aws:iam::123456789012:role/RedshiftRole'
]
)
请注意,上面的代码示例中的ARN(Amazon资源名称)应该匹配您创建的IAM角色的ARN。同时,还应相应地更改Redshift集群的标识符。