【问题标题】:Access UserPoolId from aws-cdk Stack outside of aws-cdk从 aws-cdk 外部的 aws-cdk 堆栈访问 UserPoolId
【发布时间】:2020-08-12 02:30:03
【问题描述】:

我通过 aws-cdk 将 AWS Cognito 用户池部署为 CognitoStack

现在,我想自动测试使用上述 AWS Cognito UserPool 进行身份验证的 GraphQL API。

如何以编程方式从CogntioStack 获取身份验证所需的UserPoolId

我的CognitoStack 是:

export class CognitoStack extends Stack {
  public readonly userPool: UserPool;

  constructor(scope: App, id: string, props?: StackProps) {
    super(scope, id, props);

    this.userPool = new UserPool(this, 'UserPool', {
      signInAliases: {
        email: true,
        phone: false,
        username: false,
        preferredUsername: false,
      },
      autoVerify: {
        phone: false,
        email: false,
      },
      selfSignUpEnabled: true,
    });

    this.userPool.addClient('web', {
      authFlows: {
        refreshToken: true,
        userSrp: true,
      },
    });

    new CfnOutput(this, 'UserPoolId', {
      value: this.userPool.userPoolId,
    })
  }
}

当我cdk deploy CognitoStack 时,我得到:

Outputs:
CognitoStack.UserPoolId = eu-central-1_xafasds
CognitoStack.ExportsOutputRefUserPool6BA7E5F296FD7236 = eu-central-1_xasdfdd

但是,当我检查 cdk.out/CognitoStack.template.json(在我的测试中我很容易可以 require)时,没有出现 eu-central-1_xasdfdd

【问题讨论】:

    标签: amazon-web-services aws-cdk


    【解决方案1】:

    到目前为止,我发现的最佳方法是在运行 deploy 命令时使用 --outputs-file 标志,然后我有一个包含我需要的所有字段的 json 文件。

    cdk deploy CognitoStack --outputs-file outputs.json
    

    【讨论】:

      猜你喜欢
      • 2020-12-19
      • 2021-02-18
      • 1970-01-01
      • 2020-03-05
      • 2020-12-13
      • 1970-01-01
      • 2020-10-29
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多