I am working with AWS CDK for typescript. 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:
/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);
call.
I haven't reasoned about whether or not this
in your role factory will cause mischief. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.