如何使用 CloudFormation 添加 UserPool 的资源服务器?

How to add the Resource Servers of an UserPool using CloudFormation?

如何使用 CloudFormation 在 AWS Cognito 中为用户池创建资源服务器?

在 CloudFormation 文档中,Cognito 下只有 5 项,我看不到如何配置 ResourceServer,这是否可行?

谢谢。

资源服务器以及其他项目不受 CloudFormation 支持。这是所有 supported resources 的列表。

作为 CloudFormation 的替代方案,您可以在 CloudFormation 中使用 CLI or SDK to provision and manage a Resource Server. Using the SDK, you can create a Lambda-Backed Customer Resource。然后,您可以将资源服务器添加为 CloudFormation 中的自定义资源。

您可以使用 this 通用自定义资源提供程序。

像这样使用它(未测试,但应该几乎可以工作):

  ResourceServer:
    Type: 'Custom::CognitoResourceServer'
    Properties:
      ServiceToken: !Sub '${CustomResourceLambdaArn}'
      AgentService: cognito-idp
      AgentType: client
      AgentCreateMethod: create_resource_server
      AgentUpdateMethod: update_resource_server
      AgentDeleteMethod: delete_resource_server
      AgentResourceId: Name
      AgentCreateArgs:
        UserPoolId: !Sub '${UserPool}'
        Name: 'my-resource-server'
        Identifier: 'https://foo.bar'
        Scopes:
        - ScopeName: 'my-scope'
        - ScopeDescription: 'My scope.'
      AgentUpdateArgs:
        UserPoolId: !Sub '${UserPool}'
        Name: 'my-resource-server'
        Identifier: 'https://foo.bar'
        Scopes:
        - ScopeName: 'my-scope'
        - ScopeDescription: 'My scope.'
      AgentDeleteArgs:
        Identifier: 'https://foo.bar'

API reference.

现在可以直接在 AWS::Cognito::UserPoolResourceServer 资源类型的 cloudformation 上使用。您不需要创建自定义资源来创建资源服务器。现在由cloudformation支持。参见 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolresourceserver.html 我试图将我的自定义资源更新为 cloudformation 资源,但由于某种原因,资源服务器不可更新。因此,首先我必须删除一个变更集中的自定义资源并重新创建为 AWS::Cognito::UserPoolResourceServer