Reputation: 157
Hello I would greatly appreciate any comments of the possible source of this error I am getting when using the AWS Cloud Development Kit (CDK) to deploy a Code Pipeline
I have a Typecript CDK project (cdk init --language typescript). This uses a GitHub hook to deploy on each update of a branch in my GitHub repository. This step works fine. However, the post build step happens fails with the errors
"Phase context status code: CLIENT_ERROR Message: no matching base directory path found for cdk.out"
From the code below you can see I use @aws-cdk/pipelines , SimpleSynthAction.standardNpmSynth and I think this isn't generating the cdk.out file (?). Any comments to help me resolve this issue would be much appreciated
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);
}
}
The npm 'npm run syth' just calls 'cdk synth'
I have tried running app.synth() in my /bin/my_pipeline.ts file but that doesn't fix the error.
Once again , I have googled the hell out of this and cannot resolve it so any help much appreciated. If its any use here is the buildSpec section of my output in the build logs
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": "**/*"
}
}
Upvotes: 7
Views: 6406
Reputation: 9792
I ran into the same error while on CDK v2.
In my case, I had to specify the subdirectory where CodePipeline could expect the cdk.out
file via the primaryOutputDirectory
option.
By default CodePipeline expects this dir to be in the root of the project, which is why it failed.
Example config with a subdirectory
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',
}),
});
Related docs (and props)
Upvotes: 25
Reputation: 29
For me the problem was that the cdk.out must be in the root folder of the repository, so I added a new command: mv cdk.out ../ .
Upvotes: 2
Reputation: 157
I got it working , I had to cdk destroy the deployed stack, then run 'cdk bootstrap --cloudformation-execution-policies'arn:aws:iam::aws:policy/AdministratorAccess', then make sure everything was pushed to the repo and finally run 'cdk deploy' again. I think since I hadn't done that my 'synthCommand' did not take effect.
Upvotes: 0