要在AWS CloudFormation创建的角色在身份池下拉菜单中显示,您需要确保角色具有适当的权限,并正确设置身份池的信任关系。
以下是一个可能的解决方案,其中包含一些代码示例:
Resources:
MyRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Federated: cognito-identity.amazonaws.com
Action: sts:AssumeRoleWithWebIdentity
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud": "YOUR_IDENTITY_POOL_ID"
Policies:
- PolicyName: MyRolePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- s3:ListBucket
Resource: "arn:aws:s3:::YOUR_BUCKET_NAME"
import boto3
client = boto3.client('cognito-identity')
response = client.create_identity_pool(
IdentityPoolName='MyIdentityPool',
AllowUnauthenticatedIdentities=False,
CognitoIdentityProviders=[
{
'ClientId': 'YOUR_COGNITO_APP_CLIENT_ID',
'ProviderName': 'cognito-idp.YOUR_REGION.amazonaws.com/YOUR_USER_POOL_ID',
'ServerSideTokenCheck': False
},
],
DeveloperProviderName='YOUR_DEVELOPER_PROVIDER_NAME',
SupportedLoginProviders={
'graph.facebook.com': 'YOUR_FACEBOOK_APP_ID',
'accounts.google.com': 'YOUR_GOOGLE_APP_ID'
},
# ...其他配置参数
)
# 将角色与身份池关联
response = client.set_identity_pool_roles(
IdentityPoolId='YOUR_IDENTITY_POOL_ID',
Roles={
'authenticated': 'arn:aws:iam::YOUR_ACCOUNT_ID:role/YOUR_AUTHENTICATED_ROLE',
'unauthenticated': 'arn:aws:iam::YOUR_ACCOUNT_ID:role/YOUR_UNAUTHENTICATED_ROLE'
}
)
请确保将示例代码中的“YOUR_IDENTITY_POOL_ID”、“YOUR_BUCKET_NAME”、“YOUR_COGNITO_APP_CLIENT_ID”、“YOUR_REGION”、“YOUR_USER_POOL_ID”、“YOUR_DEVELOPER_PROVIDER_NAME”、“YOUR_FACEBOOK_APP_ID”、“YOUR_GOOGLE_APP_ID”、“YOUR_ACCOUNT_ID”、“YOUR_AUTHENTICATED_ROLE”和“YOUR_UNAUTHENTICATED_ROLE”替换为您自己的值。
完成上述步骤后,您的角色应该显示在AWS管理控制台的身份池下拉菜单中。