首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >亚马逊网络服务无服务器IdentityPoolRoleAttachment

亚马逊网络服务无服务器IdentityPoolRoleAttachment
EN

Stack Overflow用户
提问于 2018-06-08 01:19:57
回答 1查看 292关注 0票数 0

因此,我正在为我的Cognito用户创建一个角色,以便能够调用API Gateway:

代码语言:javascript
复制
    IdentityAuthenticatedRole:
      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: CognitoIdentityPoolStandardUserIdentityPool
                ForAnyValue:StringLike:
                  "cognito-identity.amazonaws.com:amr": authenticated
        Policies:
          - PolicyName: CognitoGatewayExecute
            PolicyDocument:
              Version: "2012-10-17"
              Statement:
                - Effect: Allow
                  Action:
                    - "execute-api:Invoke"
                  Resource: "arn:aws:execute-api:*:*:*"
        MaxSessionDuration: 3600

然后我将角色附加到我的IdentityPoolRoleAttachment:

代码语言:javascript
复制
CognitoIdentityPoolRoleAttachment:
  DependsOn: CognitoIdentityPoolStandardUserIdentityPool
  Type: AWS::Cognito::IdentityPoolRoleAttachment
  Properties:
    IdentityPoolId:
      Fn::Join:
        - ''
        - - Ref: CognitoIdentityPoolStandardUserIdentityPool
          - ''
    Roles:
      authenticated:
        Fn:GetAtt
          - IdentityAuthenticatedRole
          - Arn

根据文档,它应该可以工作,但它当然不能:

代码语言:javascript
复制
CognitoIdentityPoolRoleAttachment - Access to Role 'Fn:GetAtt - IdentityAuthenticatedRole - Arn' is forbidden.

有人能解释一下这件事吗?

附注:由于我已经粘贴了这段代码,还有一件事:我正在使用Fn::Join,因为否则我会收到"Is not of type String“错误,有没有更好的方法来处理它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-10 02:44:34

语法错误

您的Fn::GetAtt语法有点不对劲。在FnGetAtt之间需要两个冒号,然后在该行的末尾需要一个冒号。如下所示:

代码语言:javascript
复制
      authenticated:
        Fn::GetAtt:

这将修复包含Fn:GetAtt的奇怪错误消息...真实的角色名称应该在哪里。

Fn::Join

只需使用Ref即可消除Fn::Join调用,如下所示:

代码语言:javascript
复制
  Properties:
    IdentityPoolId: 
      Ref: CognitoIdentityPoolStandardUserIdentityPool

DependsOn

DependsOn行可以,但不是必需的。CloudFormation足够聪明,可以为您找出这种依赖关系。

YAML备注

最后,虽然这归结为可读性偏好,但我通常将简短的列表(就像传递给Fn::GetAtt的列表)放在方括号中。因此,您可以替换以下内容:

代码语言:javascript
复制
  authenticated:
    Fn::GetAtt:
      - IdentityAuthenticatedRole
      - Arn

有了这个:

代码语言:javascript
复制
      authenticated:
        Fn::GetAtt: [IdentityAuthenticatedRole, Arn]

重写的

结果更短,而且可以说更容易阅读。将这些建议组合在此角色附件资源中:

代码语言:javascript
复制
CognitoIdentityPoolRoleAttachment:
  Type: AWS::Cognito::IdentityPoolRoleAttachment
  Properties:
    IdentityPoolId: 
      Ref: CognitoIdentityPoolStandardUserIdentityPool
    Roles:
      authenticated:
        Fn::GetAtt: [IdentityAuthenticatedRole, Arn]

使用Serverless 1.27.2测试

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50746902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档