CodePipeline 的云开发工具包失败,找不到 cdk.out 的匹配基本目录路径

con*_*ter 5 aws-codepipeline aws-cdk clouddevelopmentkit

您好,如果我在使用 AWS 云开发工具包 (CDK) 部署代码管道时收到此错误的可能来源,我将不胜感激。

我有一个 Typecript CDK 项目(cdk init --语言打字稿)。这使用 GitHub 挂钩在我的 GitHub 存储库中的分支的每次更新上进行部署。这一步效果很好。但是,构建后步骤发生失败并出现错误

“阶段上下文状态代码:CLIENT_ERROR 消息:找不到 cdk.out 的匹配基本目录路径”

从下面的代码中您可以看到我使用 @aws-cdk/pipelines 、 SimpleSynthAction.standardNpmSynth 并且我认为这不会生成 cdk.out 文件(?)。任何帮助我解决这个问题的评论将不胜感激

import { Construct, SecretValue, Stack, StackProps } from '@aws-cdk/core';
import * as cp from '@aws-cdk/aws-codepipeline';
import * as cpa from '@aws-cdk/aws-codepipeline-actions';
import * as pipelines from '@aws-cdk/pipelines';
import { WebServiceStage } from './webservice_stage';


    export class MyPipelineStack extends Stack {
      constructor(scope: Construct, id: string, props?: StackProps) {
        super(scope, id, props);
    
        const sourceArtifact = new cp.Artifact();
        const cloudAssemblyArtifact = new cp.Artifact();
        const sourceAction = new cpa.GitHubSourceAction({
            actionName: 'GitHub',
            output: sourceArtifact,
            oauthToken: SecretValue.secretsManager('github-token'),
            owner: 'owner',
            repo: 'repo-name',
            branch:'branch-name'
        });
    
        const synthAction = pipelines.SimpleSynthAction.standardNpmSynth({
            sourceArtifact,
            cloudAssemblyArtifact,
            buildCommand: 'npm install && npm run build && npm test',
            synthCommand: 'npm run synth'
        });
    
        const pipeline = new pipelines.CdkPipeline(this, 'Pipeline', {
            cloudAssemblyArtifact,
            sourceAction,
            synthAction
        });
        // Dev stage
        const development = new WebServiceStage(this, 'Development');
        pipeline.addApplicationStage(development);
    
      }
    }
Run Code Online (Sandbox Code Playgroud)

npm 'npm run syth' 只是调用 'cdk synt'

我尝试在 /bin/my_pipeline.ts 文件中运行 app.synth() 但这并不能解决错误。

我再一次用谷歌搜索了这个问题,但无法解决它,所以非常感谢任何帮助。如果它在这里有任何用处,那就是我在构建日志中输出的 buildSpec 部分

BuildSpec: >-
          {
            "version": "0.2",
            "phases": {
              "pre_build": {
                "commands": [
                  "npm ci"
                ]
              },
              "build": {
                "commands": [
                  "cd partnerportal_cicd_pipeline && npm install && npm run build && npm test",
                  "npm run synth"
                ]
              }
            },
            "artifacts": {
              "base-directory": "cdk.out",
              "files": "**/*"
            }
          }
Run Code Online (Sandbox Code Playgroud)

maa*_*cls 22

我在 CDK v2 上遇到了同样的错误。

就我而言,我必须cdk.out通过primaryOutputDirectory选项指定 CodePipeline 可以在其中获取文件的子目录。

默认情况下,CodePipeline 期望此目录位于项目的根目录中,这就是它失败的原因。

带有子目录的示例配置

const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
  synth: new pipelines.ShellStep('Synth', {
    input: source,
    commands: [
      'cd mysubdir',
      'npm ci',
      'npm run build',
      'npx cdk synth',
    ],
    primaryOutputDirectory: 'mysubdir/cdk.out',
  }),
});
Run Code Online (Sandbox Code Playgroud)

相关文档


con*_*ter 0

我让它工作了,我必须 cdk 销毁已部署的堆栈,然后运行 ​​'cdk bootstrap --cloudformation-execution-policies'arn:aws:iam::aws:policy/AdministratorAccess',然后确保所有内容都被推送到存储库最后再次运行“cdk部署”。我认为由于我没有这样做,所以我的“synthCommand”没有生效。