Reputation: 111
I am trying to run this function:
"cdk deploy --require-approval never"
but I am getting this error:
--app is required either in command-line, in cdk.json or in ~/.cdk.json
How can I fix this? Here's what I have in my cdk.json file:
{
"app": "npx ts-node --prefer-ts-exts bin/project-infra.ts",
}
And here's my project infrastructure code:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
// import * as sqs from 'aws-cdk-lib/aws-sqs';
export class ProjectInfraStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const layer = new lambda.LayerVersion(this, "BaseLayer", {
code: lambda.Code.fromAsset("lambda_base_layer/layer.zip")
compatibleRuntimes: [lambda.Runtime.PYTHON_3_9],
});
const apiLambda = new lambda.Function(this, "ApiFunction", {
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset("../main_app/"),
handler: "main.handler",
layers: [layer],
});
}
}
Upvotes: 11
Views: 14159
Reputation: 521
This message usually means that you aren't in the main directory of your AWS CDK project when you issue cdk synth. The file cdk.json in this directory, created by the cdk init command, contains the command line needed to run (and thereby synthesize) your AWS CDK app. For a TypeScript app the default cdk.json looks something like this:
{
"app": "npx ts-node bin/my-cdk-app.ts"
}
This is a common issue that is described in the CDK documentation:
Troubleshooting common AWS CDK issues
Upvotes: 24
Reputation: 696
it looks like ProjectInfraStack
is a cdk.Stack
, it needs to be within a cdk.App
.
// bin/project-infra.ts or you can move this declaration to its dedicated bin/main.ts. remember to update cdk.json if so.
const app = new cdk.App();
const myStack = new ProjectInfraStack(
app,
'myStack',
{
env: env,
description: 'my project infra stack',
... // other props
},
);
export class ProjectInfraStack extends cdk.Stack {
... // stack definition
}
Upvotes: 1