6

I created and built a new CDK project:

mkdir myproj
cd myproj
cdk init --language typescript
npm run build

If I try to run the resulting javascript, I see the following:

PS C:\repos\myproj> node .\bin\myproj.js
CloudExecutable/1.0

Usage:
  C:\repos\myproj\bin\myproj.js REQUEST

REQUEST is a JSON-encoded request object.

What is the right way to run my app?

4

3 回答 3

10

You don't need to run your CDK programs directly, but rather use the CDK Toolkit instead.

To synthesize an AWS CloudFormation from your app:

cdk synth --app "node .\bin\myproj.js"

To avoid re-typing the --app switch every time, you can setup a cdk.json file with:

{ "app": "node .\app\myproj.js" }

Note: A default cdk.json is created by cdk init, so you should already see it under C:\repos\myproj.

You can also use the toolkit to deploy your app into an AWS environment:

cdk deploy

Or list all the stacks in your app:

cdk ls
于 2018-07-31T14:21:39.077 回答
2

The CDK application expects a request to be provided as a positional CLI argument when you're using the low-level API (aka running the app directly), for example:

node .\bin\myproj.js '{"type":"list"}'

It can also be passed as a Base64-encoded blob instead (that can make quoting the JSON less painful in a number of cases) - the Base64 needs to be prefixed with base64: in this case.

node .\bin\myproj.js base64:eyAidHlwZSI6ICJsaXN0IiB9Cg==

In order to determine what are the APIs that are available, and what arguments they expect, you can refer to the @aws-cdk/cx-api specification.

于 2018-07-31T14:17:26.620 回答
0

Take a look at the docs by running:

cdk docs

The "Getting Started" topic will help.

于 2018-07-31T16:16:54.960 回答