import * as cdk from '@aws-cdk/core';
import * as pipelines from '@aws-cdk/pipelines';
class PipelineStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: cdk.StageProps) {
super(scope, id, props);
// Create the CDK pipeline
const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
pipelineName: 'ServerlessPipelineDemo',
synth: new pipelines.ShellStep('Synth', {
// Use a connection created using the AWS console to authenticate to GitHub
// Other sources are available.
input: CodePipelineSource.connection('taimos/cdk-serverless-demo-pipeline', 'main', {
connectionArn: 'arn:aws:codestar-connections:us-east-1:222222222222:connection/abc', // Created using the AWS console
}),
commands: [
'npm ci && npm ci --prefix lambda',
'npx cdk synth',
],
}),
});
}
}我在行const pipeline = new pipelines.CodePipeline(this,中有一个错误
错误是:' this‘类型的参数不能分配给'PipelineStack’类型的参数。类型‘PipelineStack’不能分配到'onValidate‘类型。属性’onValidate‘是受保护的,但是类型’onValidate‘不是从’构造‘派生出来的类。
package.json
{
"name": "cloud",
"version": "0.1.0",
"bin": {
"cloud": "bin/cloud.js"
},
"scripts": {
"build": "tsc && npm run copyDependencies",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",
"clean": "rm -rf ./cdk.out",
"synth": "cdk synth --app \"npx ts-node ./bin/user-manager-serverless.ts\"",
"deploy": "npm run synth && cdk deploy --app ./cdk.out/ --require-approval=never",
"buildAndDeploy": "npm run build && npm run synth && cdk deploy --app ./cdk.out/ --require-approval=never",
"copyDependencies": "copy-node-modules . node_modules_layer/nodejs/"
},
"devDependencies": {
"@aws-cdk/assert": "1.74.0",
"@aws-cdk/aws-apigateway": "1.74.0",
"@aws-cdk/aws-cognito": "1.74.0",
"@aws-cdk/aws-dynamodb": "1.74.0",
"@aws-cdk/aws-iam": "1.74.0",
"@types/aws-lambda": "^8.10.71",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"@types/uuid": "^8.3.0",
"aws-cdk": "1.74.0",
"aws-lambda": "^1.0.6",
"jest": "^26.4.2",
"ts-jest": "^26.5.0",
"ts-node": "^8.1.0",
"typescript": "~3.9.7",
"copy-node-modules": "^1.1.1"
},
"dependencies": {
"@aws-cdk/core": "1.74.0",
"aws-xray-sdk-core": "^3.2.0",
"source-map-support": "^0.5.16",
"uuid": "^8.3.2",
"@aws-cdk/aws-codepipeline": "^1.95.1",
"@aws-cdk/aws-codepipeline-actions": "^1.95.1",
"@aws-cdk/pipelines": "^1.95.1"
}
}发布于 2022-01-03 07:25:27
您的问题可能是与package.json cdk依赖关系版本不匹配。核心包( Construct位于v1中)被设置为版本1.74,与管道的版本不匹配。这有时会导致兼容性错误。要修复它,请将一个^添加到所有@aws-cdk依赖项中。
"@aws-cdk/core": "1.74.0" // exactly 1.74
"@aws-cdk/pipelines": "^1.95.1" // compatible with v1.95当前CDK版本分别为1.137和2.3.0 (截至2022年1月)。
https://stackoverflow.com/questions/70544219
复制相似问题