【发布时间】:2019-04-07 10:26:13
【问题描述】:
我正在尝试通过 cloudformation 创建我的认知资源。下面的模板工作得很好;
AWSTemplateFormatVersion: 2010-09-09
Resources:
CognitoAuthRole:
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':
Ref: CognitoIdentityPool
'ForAnyValue:StringLike':
'cognito-identity.amazonaws.com:amr': authenticated
CognitoUserPool:
Type: 'AWS::Cognito::UserPool'
Properties:
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
CognitoUserPoolClient:
Type: 'AWS::Cognito::UserPoolClient'
Properties:
UserPoolId:
Ref: CognitoUserPool
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
GenerateSecret: false
CognitoIdentityPool:
Type: 'AWS::Cognito::IdentityPool'
Properties:
AllowUnauthenticatedIdentities: true
CognitoIdentityProviders:
- ClientId:
Ref: CognitoUserPoolClient
ProviderName:
'Fn::GetAtt':
- CognitoUserPool
- ProviderName
CognitoIdentityPoolRoles:
Type: 'AWS::Cognito::IdentityPoolRoleAttachment'
Properties:
IdentityPoolId:
Ref: CognitoIdentityPool
Roles:
authenticated:
'Fn::GetAtt':
- CognitoAuthRole
- Arn
但是当我将 RoleMappings 属性添加到 CognitoIdentityPoolRoles 资源时,Cloudformation 返回错误并且无法创建堆栈。修改后的资源如下;
CognitoIdentityPoolRoles:
Type: 'AWS::Cognito::IdentityPoolRoleAttachment'
Properties:
IdentityPoolId:
Ref: CognitoIdentityPool
Roles:
authenticated:
'Fn::GetAtt':
- CognitoAuthRole
- Arn
RoleMappings:
AmbiguousRoleResolution: Deny
Type: Rules
RulesConfiguration:
Rules:
- Claim: 'custom:role'
MatchType: Equals
Value: viewer
RoleARN:
'Fn::GetAtt':
- CognitoAuthRole
- Arn
- Claim: 'custom:role'
MatchType: Equals
Value: editor
RoleARN:
'Fn::GetAtt':
- CognitoAuthRole
- Arn
正如您在上面看到的 RoleMappings 类型是规则。您可以尝试使用 Token 参数,结果不会改变。
CognitoIdentityPoolRoles:
Type: 'AWS::Cognito::IdentityPoolRoleAttachment'
Properties:
IdentityPoolId:
Ref: CognitoIdentityPool
Roles:
authenticated:
'Fn::GetAtt':
- CognitoAuthRole
- Arn
RoleMappings:
AmbiguousRoleResolution: Deny
Type: Token
不幸的是错误消息没有给出任何线索,我无法取得任何进展并卡在这个阶段。
Status Type Logical ID Status Reason
CREATE_FAILED AWS::Cognito::IdentityPoolRoleAttachment CognitoIdentityPoolRoles Internal Failure
如何使 IdentityPoolRoleAttachment 与 RoleMappings 工作?
【问题讨论】:
-
我认为 RoleMappings 应该是 RoleMapping 对象映射的一组字符串。您刚刚提到了一个 RoleMapping 对象。在此处查看示例角色映射:forums.aws.amazon.com/message.jspa?messageID=790437#790437
-
另外,看看关于动态映射的问题。也许您的问题与此有关
-
@Özgür İnce 你搞定了吗?
标签: amazon-web-services amazon-cloudformation amazon-cognito