CodeCatalyst and java based maven CDK project

0

Hi everyone

I am trying to move a project to CodeCatalyst that is using CDK for Infrastructure as code and Java as a CDK language. Maven is used as a build tool.

The project structure is like this: .

  • cdk-infrastructure --. cdk.json
  • lambda-code
  • website-code -. cdk.json

Problem 1) As the CDK deploy action is not able to execute "cdk deploy" in a sub-folder, I've changed my cdk.json in the root folder to include a directory change:

{
  "app": "cd mpaga-web-infrastructure; mvn -e -q compile exec:java",
  "context": {
    "@aws-cdk/core:enableStackNameDuplicates": "true",
    "aws-cdk:enableDiffNoFail": "true",
    "@aws-cdk/core:stackRelativeExports": "true",
    "profile" :"mpaga"
  }
}

Ask: Can we please getn option to pass the "execution directory" for the cdk-deploy (and synth) action?

Problem 2) As I did that, the project started to execute and build but failed at the first CDK step with the following error: error message from java

Do you have an idea on what the root cause for problem #2 could be? If I execute a normal build on CodePipelines (using CDK pipelines) it just works....

Thanks Johannes

3 Answers
1
Accepted Answer

The solution to your Problem 1 is in production now. The field you can use to specify the directory of your CDK stack/app is CdkRootPath. You can just provide the relative path to the cdk folder for this field. Let me know if that works for you!

profile pictureAWS
MODERATOR
AWS-Ana
answered a year ago
  • Thanks for getting back to me Ana, thats great. I was able to test this.

    Is there a chance to somewhere see the changes going into CodeCatalyst at least for this preview time?

0

Hi Johannes - We're so sorry you ran into some issues during the preview. I've checked with our team and they're working on your request/solution for Problem 1, it should be available in the next few days, and I can comment again when it's available for you to use.

For Problem 2, the CDK action executes what is specified in the "app" key , so in this case: cd mpaga-web-infrastructure; mvn -e -q compile exec:java . It's trying to execute mvn -e -q compile exec:java and failing. The error seems to say that mvn could not find the required dependency software.amazon.awscdk.core in the public maven repo, so we think it is a dependency issue in the project.

Try to execute this command locally cd mpaga-web-infrastructure; mvn -e -q compile exec:java and see if you get more information on what the problem is. If it works locally, you can try to execute cd mpaga-web-infrastructure; ls -a; mvn -e -q compile exec:java (includes the ls -a) in CodeCatalyst and it will give you more information

profile pictureAWS
MODERATOR
AWS-Ana
answered a year ago
  • Hi there, thanks for the great and detailed answer. Would be glad if you could get back to me once the change for 1 is deployed.

    You are correct, I copy/pasted a wrong pom.xml and had a wrong version for the dependencies. I've fixed that, but I am now facing the next problem: 2022-12-03T22:34:14.3825655Z [22:34:14] Reading cached notices from /root/.cdk/cache/notices.json 2022-12-03T22:34:14.3958505Z 2022-12-03T22:34:14.3958851Z [22:34:14] Error: ENOENT: no such file or directory, open 'cdk.out/manifest.json' 2022-12-03T22:34:14.3958984Z at Object.openSync (node:fs:590:3)

  • This problem seems to be related to problem#1, I am trying to workaround it with creating the folder manually....lets see...

0

Sorry for the delay. For the last problem you mentioned, When the CDK synthesizes a template, it copies the artifacts under the cdk.out directory. Based on what you are experiencing, this would suggest that your CDK synth is failing for some reason. It could be that your bin/app.ts file is not initializing the stack in your CDK code, example:

const app = new cdk.App();
new MyStack(app, 'MyStack');

or one of many other reasons listed out on GitHub in the aws-cdk issues resources on GitHub. I would suggest checking there for other possible reasons as there are a few that are similar to what you have shared but it's hard for me to see if any of those would solve your problem. Let me know if you figure it out and I'll respond when we have the fix in place for Problem 1

profile pictureAWS
MODERATOR
AWS-Ana
answered a year ago
  • Hi Ana

    thanks for getting back to me - I've verified that "cdk synth" works locally (I am using a CDK for Java)... If've changed my cdk.json to be "app": "ls -al; cd mpaga-web-infrastructure; ls -la; whoami; ls -al cdk.out;mvn -e -q compile exec:java",and I can see that the cdk.out folder exists and the stacks have been created - but when it tries to do the deploy after the synth it refers to the cdk.out directory in the root and not in my sub-folder.... I'll wait for problem1 solution and then hope that it gets resolved with that? ;) Johannes

  • the cdk deploy action now works with this cdk.json: { "app": "ls -al; cd mpaga-web-infrastructure; ls -la; whoami; ls -al cdk.out;mvn -e -q compile exec:java; cp -r cdk.out/* ../cdk.out", "context": { "aws-cdk:enableDiffNoFail": "true", "@aws-cdk/core:stackRelativeExports": "true", "profile" :"mpaga" } }

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions