【发布时间】:2020-07-26 11:02:10
【问题描述】:
我正在使用 AWS CDK TypeScript。我正在尝试在 cdk 中创建一个认知用户池。但它在“this”处显示以下警告,
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'RegionalCognitoCreation' is not assignable to type 'Construct'.
Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.ts(2345)
我的代码如下,
import * as cdk from '@aws-cdk/core';
import { UserPool } from '@aws-cdk/aws-cognito'
export class CognitoCreation extends cdk.Construct {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new UserPool(this, 'myuserpool', {
userPoolName: 'my-userpool',
});
}
}
我的 package.jso 如下所示,
{
"name": "******",
"version": "0.1.0",
"bin": {
"regional-infrastructure": "bin/*****.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk"
},
"devDependencies": {
"@aws-cdk/assert": "1.53.0",
"@types/jest": "^25.2.1",
"@types/node": "10.17.5",
"jest": "^25.5.0",
"ts-jest": "^25.3.1",
"aws-cdk": "1.53.0",
"ts-node": "^8.1.0",
"typescript": "~3.7.2"
},
"dependencies": {
"@aws-cdk/aws-cloudformation": "^1.53.0",
"@aws-cdk/aws-cognito": "^1.54.0",
"@aws-cdk/aws-dynamodb": "^1.53.0",
"@aws-cdk/aws-elasticsearch": "^1.53.0",
"@aws-cdk/aws-iam": "^1.53.0",
"@aws-cdk/aws-lambda": "^1.53.0",
"@aws-cdk/aws-lambda-event-sources": "^1.53.0",
"@aws-cdk/aws-sns": "^1.53.0",
"@aws-cdk/aws-sns-subscriptions": "^1.53.0",
"@aws-cdk/core": "1.53.0",
"@aws-cdk/custom-resources": "^1.53.0",
"aws-sdk": "^2.716.0",
"source-map-support": "^0.5.16"
}
}
我已经运行了“npm install”,并且在节点模块中添加了 cognito 和其他模块。我尝试用“范围”改变“这个”,但这对我不起作用。我的cdk版本是1.46.0 (build 63860b2)
【问题讨论】:
-
您能否添加更多信息:使用的 CDK 版本,使用的依赖项列表(例如粘贴 package.json),您是否运行了“npm install”?如上所述尝试用户池时我没有遇到任何问题。
-
请在上述问题中找到 package.json 和 cdk 版本。我确实运行了“npm install”。
-
你的课程应该扩展
cdk.Stack而不是cdk.Construct吗? -
但是我想将此资源创建为与其他资源相同的堆栈的一部分...我仍然尝试将 cdk.Construct 更改为 cdk.Stack 但没有进行任何更改。
标签: typescript amazon-web-services aws-cdk