CDK Continuous Integration/Continuous Deployment pipeline encountering difficulties locating references within stack for deployment

My goal is to set up a cdk cicd pipeline for an app that already has a cdk stack and deploys successfully manually with cdk deploy. I want the cdk pipeline to automatically deploy the stack whenever changes are pushed to the main branch so that it's not a manual process.

I've been following both the AWS tutorial and this blog, which have helped me progress quite far.

My folder structure looks like this:

https://i.sstatic.net/wDFnB.png

The stack I want to deploy via the pipeline is located in lib/tagworx-rfid-cdk-stack.ts

Running cdk deploy from the root folder deploys this stack without any issues.

The CICD Pipeline stack is in /infra/lib.

When I try to deploy from there, it works for a simple test. However, when I try to add the main stack that I want the CICD pipeline to deploy, I encounter the following error:

Error: Cannot find asset at root/infra/lib/resources/layers/helper. I believe this error is related to the layer I have in the main stack that I want the CICD pipeline to deploy. When it tries to execute lambda.Code.fromAsset('resources/layers/helper'), the process is still in the cicd location instead of the main stack location, causing it to not find the reference.

lib/tagworx-rfid-cdk-stack.ts - this is the stack I want the CICD pipeline to deploy

export class TagworxRfidCdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const layer = new lambda.LayerVersion(this, 'HelperLayer', {
      code: lambda.Code.fromAsset('resources/layers/helper'),
      description: 'Axios and other helper functions',
      compatibleRuntimes: [lambda.Runtime.NODEJS_16_X],
    });
...

/infra/lib/infra-stack.ts

export class InfraStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: PipelineAppProps) {
    super(scope, id, props);

    const buildCodeArtifactPolicy: PolicyStatement[] = [
      // some policies removed for brevity
    ];

    const buildEnvironmentForStep: BuildEnvironment = {
      computeType: ComputeType.SMALL,
      buildImage: LinuxBuildImage.STANDARD_6_0,
      privileged: true,
    };

    const branch = 'main'

    const codeBuildStepSynth = new CodeBuildStep(`${props.name}-build-step`, {
      input: CodePipelineSource.connection(`${props.ghRepository}`, branch, {
        connectionArn: props.codestarConnectionArn,
      }),
      installCommands: ["npm install -g npm@latest"],
      commands: ["npm install", "npm run build", "npx cdk synth" ],
      rolePolicyStatements: buildCodeArtifactPolicy,
      buildEnvironment: buildEnvironmentForStep,
      primaryOutputDirectory: "cdk.out",
    });

    const codeBuildStepArtifact = new CodeBuildStep(
      `${props.name}-artifact-publish-step`,
      {
        commands: [
          "npm ci",
        ],
        rolePolicyStatements: buildCodeArtifactPolicy,
        buildEnvironment: buildEnvironmentForStep,
      }
    );

    const pipeline: CodePipeline = new CodePipeline(
      this,
      `${props?.name}-code-pipeline`,
      {
        pipelineName: `${props.name}-pipeline`,
        selfMutation: true,
        synth: codeBuildStepSynth,
      }
    );
    
    const env = { account: '1111111111', region: 'eu-west-1' };
    const stackName = `dev-rfid-stack-${env.region}`;
    
    // THIS 👇 is what has broken the cdk deploy, without this it deploys the cicd pipeline,
    // but I think I need this to actually deploy the stack?
    pipeline.addStage(new InfraAppStage(this, stackName, {
      env: env
    }));

    pipeline.addWave(`${props.name}-code-artifact-publish`, {
      post: [codeBuildStepArtifact],
    });
    
    pipeline.buildPipeline();
  }
}

/infra/lib/infra-app-stage

export class InfraAppStage extends cdk.Stage {

    constructor(scope: Construct, id: string, props?: cdk.StageProps) {
      super(scope, id, props);

      const lambdaStack = new TagworxRfidCdkStack(this, 'my-test-stack');
    }
}

When I add the additional app stage:

pipeline.addStage(new InfraAppStage(this, stackName, {
      env: env
    }));

and attempt to deploy, I encounter the error.

It seems to be looking in the cicd folder for references in the actual stack I want to deploy?

I expected the references to be aware of their location?

Answer â„–1

Please include the complete file path to the Lambda code:

import path from "path";
//...

const layer = new lambda.LayerVersion(this, "HelperLayer", {
  code: lambda.Code.fromAsset(path.join(__dirname, "path/to/helper")),
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to migrate my current firebase/react project to typescript. Any tips on how to batch.update?

Having difficulty resolving a typescript error related to batch.update in my code. const batch = db.batch(); const listingDoc = await db.collection("listings").doc(listingID).get(); const listingData = listingDoc.data( ...

Issue with displaying response data from Angular API in the template

I am retrieving categories from the backend and trying to display them in a table. However, there seems to be an issue with my code as no data is showing up in the table. Although the getFournisseurs method is successfully fetching 5 items from the backen ...

Setting up @cypress/code-coverage with Angular and TypeScript: A comprehensive guide

When following the instructions in Cypress documentation for @cypress/code-coverage, it recommends using the following code... // cypress/support/e2e.js import '@cypress/code-coverage/support' ...as well as... // cypress.config.ts import { defin ...

Generating AWS presigned URLs for objects stored in an S3 bucket

Our team uploads various types of content to a secure S3 bucket. When we generate and access presigned URLs for MP4 videos and images, everything works smoothly in the browser. However, when trying to access SWF and PDF files, the browser prompts us to dow ...

Exploring the functionality of window.matchmedia in React while incorporating Typescript

Recently, I have been working on implementing a dark mode toggle switch in React Typescript. In the past, I successfully built one using plain JavaScript along with useState and window.matchmedia('(prefers-color-scheme dark)').matches. However, w ...

Encountering problem with npm ERR! peer @angular/common@"^12.0.0" while trying to install @ng-bootstrap/[email protected]

Encountering an issue during the deployment of my Angular application. I added the @ng-bootstrap/ng-bootstrap package, but there seems to be a dependency resolution problem causing the issue. 22-Dec-2022 07:03:47 npm ERR! Could not resolve dependency: 2 ...

What could be the reason behind TS showing the error "Type 'MyMedicine[]' cannot be assigned to type 'MyMedicine' as a parameter"?

Here is an interface I have created: export interface MyMedicine { _id: String; name: String; quantity: Number; time: String; } This snippet shows my Angular service used for posting data: postMed(newMed): Observable<MyMedicine[]>{ var he ...

Angular 6 component experiencing issues with animation functionality

I've implemented a Notification feature using a Notification component that displays notifications at the top of the screen. The goal is to make these notifications fade in and out smoothly. In my NotificationService, there's an array that holds ...

What is the best way to assign default values when destructuring interfaces within interfaces in TypeScript?

My goal here is to create a function that can be used with or without arguments. If arguments are provided, it should work with those values; if not, default values should be used. The issue I'm facing is that although there are no TypeScript errors ...

I am looking for a way to convert the date format from "yyyy-MM-dd" to "dd-MM-yyyy" in NestJs

I need help with changing the date format from "yyyy-MM-dd" to "dd-MM-yyyy". Currently, my entity code looks like this: @IsOptional() @ApiProperty({ example: '1999-12-12', nullable: true }) @Column({ type: 'date', nullable: true } ...

Creating dynamic keys to insert objects

In my coding project, I am dealing with an empty array, a value, and an object. Since there are multiple objects involved, I want to organize them into categories. Here is an example of what I envision: ARRAY KEY OBJECT OBJECT KEY OBJECT ...

Is it possible to have code highlighting and intellisense features while typing within backticks in Visual Studio Code?

I am looking for a way to enable code highlighting and IntelliSense within backticks (``) in a .ts file in Visual Code. For example: let html =`<div><span>Hello</span></div>`; If you have experience with this feature in Atom or ar ...

The Angular 6 View does not reflect changes made to a variable inside a subscribe block

Why isn't the view reflecting changes when a variable is updated within a subscribe function? Here's my code snippet: example.component.ts testVariable: string; ngOnInit() { this.testVariable = 'foo'; this.someService.someO ...

Utilizing a string as an argument in a function and dynamically assigning it as a key name in object.assign

Within my Angular 5 app written in TypeScript, I have a method in a service that requires two arguments: an event object and a string serving as the key for an object stored in the browser's web storage. This method is responsible for assigning a new ...

Determining when to include @types/packagename in React Native's dev dependencies for a specific package

Just getting started with React Native using typescript. Take the package vector icon for example, we need to include 2 dependencies: 1. "react-native-vector-icons": "^7.1.0" (as a dependency) 2. "@types/react-native-vector-icons": "^6.4.6" (as a dev ...

NextJs 13 unveils its cutting-edge dynamic sitemap feature

I am currently working on implementing a dynamic sitemap for NextJs 13.4.6, referring to the guide available at . However, I have encountered an issue with the code provided towards the end of the article which is supposed to generate a sitemap for NextJS ...

Universal Enum variable

I came up with a function that accepts a specific type of enum value to determine a color to pass as a prop to another function. However, I want the flexibility to throw a different enum at my function. I thought about using a generic type, but TypeScript ...

What is the recommended approach in Angular for unassigned @Input() variables when using TypeScript strict mode?

Issue at Hand After upgrading my Angular version from 10 to 13, I encountered a problem with the new TypeScript strict compiler mode. The upgrade required me to assign values to all declared variables upon initialization, causing issues with properties de ...

What is the reason behind AWS Amplify not acknowledging the updated node version?

Recently, I upgraded NODE on my local machine and made the switch from create-react-app to nextjs. However, upon pushing the code to AWS Amplify, an error occurred: Error <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294e4844 ...

Clicking a button in React requires two clicks to update a boolean state by triggering the onClick event

I have a React functional component with input fields, a button, and a tooltip. The tooltip is initially disabled and should only be enabled and visible when the button is clicked and the input fields contain invalid values. The issue I'm facing is t ...