使用 AWS CDK,如何在创建资源后更改资源?

问题描述 投票:0回答:1

我正在使用 AWS CDK 创建一个带有一些 lambda 触发器的 Cognito 用户池。其中一个 lambda 需要附加一个角色,该角色取决于用户池 arn。我通过将用户池添加到这个特定的 lambda 依赖项来实现此行为。问题是我必须从用户池的 lambda 触发器中删除这个 lambda 以避免循环依赖。我正在努力寻找一种在创建 lambda 后添加此触发器的方法。任何帮助将非常感激。

    const userPool = new cg.UserPool(this, "users", {
      ...
      lambdaTriggers: {
        ...lambdas with no dependencies
      },
    });

    // makeLambda is a custom function that returns new lambda.Function
    const postAuthentication = makeLambda(this, "postAuthentication");

    postAuthentication.addToRolePolicy(
      new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        actions: ["cognito-idp:AdminUpdateUserAttributes"],
        resources: [userPool.userPoolArn],
      })
    );

    postAuthentication.node.addDependency(userPool);

    // This line of code is what is causing the circular dependency, if I could find a
       a way to delay this step until after the creation of the lambda it would
       solve the problem
    userPool.addTrigger(cg.UserPoolOperation.POST_AUTHENTICATION, postAuthentication);


amazon-web-services aws-lambda aws-cloudformation amazon-cognito aws-cdk
1个回答
0
投票

您需要自己将

userPool.userPoolArn
构造为字符串,而不是引用资源。您需要能够预测准确的 arn,这可能需要对用户池的名称进行硬编码。

© www.soinside.com 2019 - 2024. All rights reserved.