简体   繁体   English

AWS CDK stack.regionalFact 不是 function

[英]AWS CDK stack.regionalFact is not a function

I am working with AWS CDK for typescript.我正在为 typescript 使用 AWS CDK。 I have my stack which consists of only one role我的堆栈只包含一个角色

export class ModelServingStack extends BaseStack {
  constructor(scope: cdk.Construct, props: StackCommonProps, stackConfig: any) {
    const role: iam.IRole = this.createIamRole(`ModelEndpoint-Role`);
  }

  private createIamRole(roleBaseName: string): iam.IRole {
    return new iam.Role(this, "MyRole", {
      assumedBy: new iam.ServicePrincipal("sns.amazonaws.com"),
    });
  }
}

When I run the command to deploy cdk deploy I get the following error:当我运行命令部署cdk deploy时,出现以下错误:


/workspaces/Zeus/node_modules/@aws-cdk/aws-iam/lib/principals.ts:540
    return stack.regionalFact(
                 ^
TypeError: Resolution error: Resolution error: Resolution error: Resolution error: stack.regionalFact is not a function.
Object creation stack:
  at stack traces disabled.
Object creation stack:
  at stack traces disabled..
    at ServicePrincipalToken.resolve (/workspaces/Zeus/node_modules/@aws-cdk/aws-iam/lib/principals.ts:540:18)
    at RememberingTokenResolver.resolveToken (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/resolvable.ts:80:24)
    at RememberingTokenResolver.resolveToken (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:286:18)
    at resolve (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:212:51)
    at Object.resolve [as mapToken] (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:119:77)
    at TokenizedStringFragments.mapTokens (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/string-fragments.ts:65:33)
    at RememberingTokenResolver.resolveString (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/resolvable.ts:99:22)
    at RememberingTokenResolver.resolveString (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:290:23)
    at resolve (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:170:48)
    at Object.resolve (/workspaces/Zeus/node_modules/@aws-cdk/core/lib/private/resolve.ts:119:77)

Any idea?任何想法? Thank you in advance.先感谢您。

One problem is that your constructor is missing the super(scope, id, props);一个问题是您的构造函数缺少super(scope, id, props); call.称呼。

I haven't reasoned about whether or not this in your role factory will cause mischief.我还没有推理this在你的角色工厂中是否会引起恶作剧。 But in any case, it is idiomatic CDK to define your constructs in the Stack constructor, where this will certainly refer to your Stack instance.但无论如何,在 Stack 构造函数中定义您的构造是惯用的 CDK ,其中this肯定会引用您的Stack实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM