Deploying code from an S3 bucket to CodeCommit using AWS CDK

During the implementation of my CDK Stack, I encountered an issue when creating a Bucket, uploading files to it, and then creating a CodeCommit repository to store those files. Everything was going smoothly until I tried to create a new codecommit.CfnRepository and received the following error:

CREATE_FAILED        | AWS::CodeCommit::Repository | CfnRepository
Not Found (Service: Amazon S3; Status Code: 404; Error Code: 404 Not Found;
Request ID: 2608A90CD11E9729; S3 Extended Request ID: 1iVrjbDpcwqSrsNc7s/aF
9UpNMg0DGe9ABTAJMuoRkA3f9qSYMqVN0sWeLRdT6ETck/DRx6dDCM=)

I found that splitting the s3 creation/deployment and Repository creation into two separate stacks resolved the issue, but if they are in one constructor, the CDK deployment fails.

Below is the code snippet that I am using:

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

    const myBucket = new s3.Bucket(this, 'Bucket', {
      bucketName: name,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
    });

    new s3deploy.BucketDeployment(this, 'DeployFiles', {
      sources: [s3deploy.Source.asset('./lib/Files.zip')],
      destinationBucket: myBucket
    });

    new codecommit.CfnRepository(this, 'CfnRepository' , {
      repositoryName: 'MyFetucinyName',
      code: {
        s3: {
          bucket: name,
          key: 'Files/SourceCode.zip'
        }
      }
    });
  }
}

If anyone has any ideas on how to make this work, I would greatly appreciate it.

Answer №1

It seems like you are waiting for the BucketDeployment to finish before proceeding. To achieve this, consider adding a dependency as shown below:

    const s3deploy = new s3deploy.BucketDeployment(this, 'DeployFiles', {...});

    const ccr = new codecommit.CfnRepository(this, 'CfnRepository' , {...});

    ccr.node.addDependency(s3deploy);

However, keep in mind that according to the AWS CDK documentation, s3deploy.BucketDeployment unzips the archive into the bucket.

So, ensure that your "key: 'Files/SourceCode.zip'" points to uncompressed content. Alternatively, you can reference the directory containing your zip file for intact upload, like this:

    new s3deploy.BucketDeployment(this, 'DeployFiles', {
      sources:  [s3deploy.Source.asset('./lib')],
      destinationBucket: myBucket
    });

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

Filtering the data in the table was successful, but upon searching again, nothing was found. [Using Angular, Pagination, and

Having a table with pagination, I created a function that filters the object and displays the result in the table. The issue arises when I perform a new search. The data from the initial search gets removed and cannot be found in subsequent searches. Bel ...

The NextAuth implementation in API routes seems to be causing issues as the unstable_getServerSession and getToken functions consistently

Struggling with utilizing the unstable_getServerSession in a nextJS API route after switching from a custom authentication method. Wondering if I may have misconfigured JWT or missing something obvious. Referenced the tutorial "Securing API routes&qu ...

Compiling TypeScript: Using the `as` operator to convert and then destructure an array results in a compilation error, requiring an

I am currently utilizing TypeScript version 2.9.2. There is a static method in a third-party library called URI.js, which is declared as follows: joinPaths(...paths: (string | URI)[]): URI; I have a variable named urlPaths that is defined as urlPaths: s ...

The system could not locate the time zone identifier 'Pacific Standard Time' on the current device

After deploying my application on AWS Lambda, I encountered an error while trying to access the time zone: 'The time zone ID 'Pacific Standard Time' was not found on the local computer.' I need assistance on how to add time zones on La ...

Outputting undefined values when processing an http post array

I seem to have encountered a major issue. Despite my efforts, I am seeing an undefined value when trying to display this JSON data. {"StatusCode":0,"StatusMessage":"OK","StatusDescription":{ "datas": [ {"sensor_serial":"SensorSerial1", "id":"11E807676E3F3 ...

Identifying Angular 2 templates post-file separation: a step-by-step guide

I am currently trying to figure out how to initiate a project in Angular 2 and have encountered an issue. Following the steps outlined in this Angular 2 guide, I was able to separate my .ts files from .js files by configuring my 'temp' directory ...

Tips for accentuating a chosen cell

When selecting an item from the list, I want to highlight the selected item. How can I achieve this? Here is the code snippet: <li class="nav-item dropdown"> <div class="dropdown"> <a class="nav-link dropdown-toggle text-white" hre ...

Angular 4's unique feature is the ability to incorporate multiple date pickers without the

Is there a way to implement a multiple date picker using Angular 4 and TypeScript only? I came across one solution but it seems to only support Angular 1. Thank you in advance! ...

Passing Props Down in a React Component Wrapper

Currently, I am constructing a Component Wrapper using React. The aim is to enclose any components requiring specific data with this wrapper to deliver the necessary data when rendering the component. However, my primary challenge lies in passing down othe ...

Alter the style type of a Next.js element dynamically

I am currently working on dynamically changing the color of an element based on the result of a function //Sample function if ("123".includes("5")) { color = "boldOrange" } else { let color = "boldGreen" } Within my CSS, I have two clas ...

Slim specific assigned parameter

Here is some code to analyze: type T = 'a' | "b" type M = { a: 1, b: 2 } function a(a: 'a') {} function m1(a: 1) {} function f<TT extends T>(t: TT, p: M[TT]) { switch (t) { case "a": { a(t) ...

disable the button border on native-base

I'm attempting to enclose an icon within a button, like so: <Button style={styles.radioButton} onPress={() => { console.log('hdjwk'); }}> <Icon ...

A guide to sending HTTP requests using TypeScript

Is it possible to make API calls from TypeScript and use "async-await" with it? I am currently in the process of converting React code to TypeScript. Currently utilizing Axios for making HTTP Requests ...

Angular: Converting JSON responses from HttpClient requests into class instances

I am facing an issue with the following code: public fetchResults(searchTerm: string): Observable<Array<SearchResult>> { let params = new HttpParams().set('searchTerm', searchTerm); return this.http .get<Array< ...

The error occurred due to an invalid regular expression when trying to create a route with route parameters

In my development process, I have a specialized class for creating routes and another class for bundling these routes before adding them to an express app or router. However, I encountered a problem with my route class when I attempted to create a route wi ...

How can I effectively implement *ngFor in Angular while utilizing the Async pipe?

Hey there, I'm facing some issues with utilizing the asynchronous ngFor feature. I have a basic example where an array of objects is fetched from a server during onInit, and once it arrives, I want to iterate over it. Here's how it's impleme ...

The object's key values were unexpectedly empty despite containing data

There's an issue with my object - it initially gets key values, but then suddenly loses them all. All the key values become empty and a message appears in the console for the object: "this value was evaluated upon first expanding. it may have ch ...

ANGULAR - Creating Specific Query Parameters When Navigating Backwards

Is there a way to automatically include query parameters when navigating back to the previous page using the browser's default back button? For instance, when calling a customer-hierarchy component view, you can add query parameters like this: <a ...

Creating a dynamic array in an Angular 2 service for real-time changes monitoring by a component

I am facing an issue where my NotificationsBellComponent is not receiving changes to the array in the service even though the _LocalStorageService is returning data correctly. Q) How can I ensure that my component receives updates when the service collect ...

The VSCode Extension fails to launch after being packaged

I'm currently working on a straightforward VSCode extension that scans the active open file for any comments containing "//TODO: " and then presents a list of all TODO comments in a webview sidebar tab. While I have a functional prototype that runs s ...