Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run cdk synthesis? #567

Open
kenchoong opened this issue Feb 3, 2023 · 6 comments
Open

How to run cdk synthesis? #567

kenchoong opened this issue Feb 3, 2023 · 6 comments

Comments

@kenchoong
Copy link

I want to run cdk synth as stated here
https://docs.aws.amazon.com/cdk/v2/guide/cli.html#cli-synth

But when run this

 yarn cdk synth

I get this error:

$ /e/node_modules/.bin/cdk synthesize

--app is required either in command-line, in cdk.json or in ~/.cdk.json
error Command failed with exit code 1.

Then I figured out this plugin only 2 command is available, which is deploy and destroy.

Any chance I can run cdk synth ?

@t-karaca
Copy link

I made a workaround for this like following:

Assuming you created your cdk project in packages/cdk-stack, you can add another run target called synth in packages/cdk-stack/project.json. The resulting file should look like the following:

{
  "name": "cdk-stack",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
  "sourceRoot": "packages/cdk-stack/src",
  "targets": {
    "synth": {
      "executor": "nx:run-commands",
      "options": {
        "command": "cdk synth",
        "cwd": "packages/cdk-stack"
      }
    },
    "deploy": {
      "executor": "@ago-dev/nx-aws-cdk-v2:deploy",
      "options": {}
    },
    "destroy": {
      "executor": "@ago-dev/nx-aws-cdk-v2:destroy",
      "options": {}
    },
    "bootstrap": {
      "executor": "@ago-dev/nx-aws-cdk-v2:bootstrap",
      "options": {}
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["packages/cdk-stack/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "packages/cdk-stack/jest.config.ts",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

Then you can just run nx run cdk-stack:synth.

@adrian-goe
Copy link
Owner

OH, im sorry, I saw this just now. Somehow this got lost in the stress of moving houses.

I will change the core a bit and pass all things down to the cdk. Unfortunately, this might take 1 or 2 weeks until i have more time for that.

@sandrokeil
Copy link

@adrian-goe Thank you very much for this nx plugin.

In order to make the synth command work with library packages, it's also needed to change the app entry in cdk.json to "app": "npx ts-node -r tsconfig-paths/register --prefer-ts-exts bin/main.ts" and to install npm install --save-dev tsconfig-paths.
It would also be nice to have a typescript build command, but I was not able to figure it out because it looks like the ts-node config ignores tsconfig-paths.

@willredington
Copy link

+1 on this. Nx is truly an incredible platform, especially for something like IAC, and synth support would be really great to have

@rckgomz
Copy link

rckgomz commented Sep 13, 2023

+1

@teaforchris
Copy link

As a follow on from @sandrokeil 's comment (which is a perfect workaround for the missing :synth command!), I found I had to replace all references of

"executor": "@ago-dev/nx-aws-cdk-v2:foo",
"options": {}

with

"executor": "nx:run-commands",
"options": {
  "command": "cdk foo",
  "cwd": "apps/cdk"
}

(where apps/cdk is just the path to my main cdk app called cdk; yours might be different)

Otherwise running any nx foo cdk command littered the project root with cdk.context.json and cdk.out/* files and not obey the output property in /apps/cdk/cdk.json.

This means all my commands now have to be nx run cdk:foo and not nx foo cdk as per the docs.

Not sure if this is also a bug as it does mean bypassing all the nx goodness? It could well be that I have something misconfigured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants