简体   繁体   中英

Default Stack not correct while using AWS CDK typescript

I wanted to confirm if the default stack VPC generated by cdk in./lib is correct. Here are my steps -

%% cdk --version
1.83.0 (build 827c5f4)
%% tsc --version
Version 4.1.3
mkdir vpc
cd vpc 
cdk init app --language=typescript

Now, if I look at the file./lib/vpc-stack.ts

import * as cdk from '@aws-cdk/core';

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

    // The code that defines your stack goes here
  }
}

However, the file should have been ( I think)

//vpc-stack.ts
import {App, Stack, StackProps} from '@aws-cdk/core';
import {Peer, Port, SecurityGroup, SubnetType, Vpc} from '@aws-cdk/aws-ec2'

export class VpcStack extends Stack {
    readonly vpc: Vpc;
    readonly ingressSecurityGroup: SecurityGroup;
    readonly egressSecurityGroup: SecurityGroup;

    constructor(scope: App, id: string, props?: StackProps) {
        super(scope, id, props);

        //Place resource definitions here.
    }
}

Really appreciate if anyone could point the missing step.

Thanks !

app template creates an empty stack definition: https://docs.aws.amazon.com/cdk/latest/guide/cli.html#cli-init

TEMPLATE is an optional template. If the desired template is app, the default, you may omit it. The available templates are:

Template | Description
app (default) | Creates an empty AWS CDK app.
sample-app | Creates an AWS CDK app with a stack containing an Amazon SQS queue and an Amazon SNS topic.

The templates use the name of the project folder to generate names for files and classes inside your new app.

The stack definition without resources is the expected command output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM