简体   繁体   English

使用 AWS CDK typescript 时默认堆栈不正确

[英]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.我想确认 cdk in./lib 生成的默认堆栈 VPC 是否正确。 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现在,如果我查看文件 ./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 app模板创建一个空堆栈定义: 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.没有资源的堆栈定义是预期的命令 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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