【发布时间】:2022-01-15 19:43:46
【问题描述】:
我有一个烧瓶应用程序,我正在尝试将它部署到登陆区域,使用 CDK(Typescript,v2.5.0)作为 Fargate 实例。
登陆区是我需要使用的现有 VPC,带有独立子网和私有子网。
我已经尝试了所有我能想到的组合来让负载平衡器(尝试了应用平衡和网络平衡)来使用隔离子网,但没有任何效果。
我从cdk synth 得到的错误是
deploy/node_modules/aws-cdk-lib/aws-ec2/lib/vpc.ts:401
throw new Error(`There are no '${subnetType}' subnet groups in this VPC. Available types: ${availableTypes}`);
^
*Error: There are no 'Public' subnet groups in this VPC. Available types: Isolated*
这是我的代码:
import * as cdk from "@aws-cdk/core";
import { Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as ecs from "aws-cdk-lib/aws-ecs";
import * as ecsp from "aws-cdk-lib/aws-ecs-patterns";
export class DeployStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const defaultnonprodVPC = "existing-vpc";
const defaultVPC = ec2.Vpc.fromLookup(this,
"defaultVPC",
{
isDefault: false,
vpcId: defaultnonprodVPC,
tags: { "aws-cdk:subnet-type": "isolated" }
}
);
const knownIsolatedSubnets = defaultVPC.isolatedSubnets;
const monitoringSubnets = defaultVPC.selectSubnets(
{
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
}
);
const networkBalancedFargateService = new ecsp.NetworkLoadBalancedFargateService(this,
"ConnectorMonitorService", {
memoryLimitMiB: 512,
desiredCount: 1,
cpu: 256,
taskImageOptions: {
image: ecs.ContainerImage.fromAsset("../src")
},
taskSubnets:
{
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
},
vpc: defaultVPC
});
}
}
将taskSubnets 更改为任何一个
{ subnets: { knownIsolatedSubnets } }
或
subnetGroupName: "subnet-existing-subnet-name"
或
monitoringSubnets
对cdk synth 没有影响。设置 assignPublicIp: false 也不会改变任何事情。
我做错了什么或错过了什么?
【问题讨论】:
-
cdk.context.json是否缓存了预期的 vpc 和子网 context?另外,在合成之前仔细检查您是否使用tsc编译打字稿。
标签: flask aws-cdk aws-fargate