I am creating a pipeline using AWS CDK. I first create my stack which consists in a vpc and an rds, I export the vpc object and use it in a post CodeBuildStep which migrates the database:
export class CdkPipelineStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props)
const repo = new codecommit.Repository(this, 'CloudFrontCDKRepo', {
repositoryName: 'backend',
})
const pipeline = new CodePipeline(this, 'Pipeline', {
crossAccountKeys: false,
pipelineName: 'MyPipeline2',
synth: new ShellStep('Synth', {
input: CodePipelineSource.codeCommit(repo, 'cdk'),
commands: ['cd cdk', 'npm ci', 'npm run build', 'npx cdk synth'],
primaryOutputDirectory: 'cdk/cdk.out',
}),
})
const deploy = new DevStage(this, 'Deploy-dev')
const deployStage = pipeline.addStage(deploy)
deployStage.addPost(
new CodeBuildStep('SLS Deploy', {
commands: ['./build.sh'],
vpc: deploy.vpc
}),
)
}
}
However I am getting the following error:
Stack "MyPipelineStack" cannot consume a cross reference from stack "MyPipelineStack/Deploy-dev/S3Stack". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack
How can I correctly import the vpc here? And if this is not possible, how do I run a codebuildstep as a separate stack which executes only after the main stack has finished?