希望有人能在这里帮助我,根据AWS文档,如果是我声明我的VPC,然后我不应该宣布‘容量’,但是当我运行CDK synth时,我得到以下错误.
抛出新错误(
Validation failed with the following errors:\n ${errorList}); 错误:验证失败,出现以下错误:此服务的PrerenderInfrasctutureStack/preRenderApp/Service群集需要Ec2容量。在集群上调用addXxxCapacity()。
这是我的密码。(我希望内森·派克看到这个)
const ec2 = require('@aws-cdk/aws-ec2');
const ecsPattern = require('@aws-cdk/aws-ecs-patterns');
const ecs = require('@aws-cdk/aws-ecs');
class PrerenderInfrasctutureStack extends cdk.Stack {
/**
*
* @param {cdk.Construct} scope
* @param {string} id
* @param {cdk.StackProps=} props
*/
constructor(scope, id, props) {
super(scope, id, props);
const myVPC = ec2.Vpc.fromLookup(this, 'publicVpc', {
vpcId:'vpc-xxx'
});
const preRenderApp = new ecsPattern.ApplicationLoadBalancedEc2Service(this, 'preRenderApp', {
vpcId: myVPC,
certificate: 'arn:aws:acm:ap-southeast-2:xxx:certificate/xxx', //becuase this is spcified, then the LB will automatically use HTTPS
domainName: 'my-dev.com.au.',
domainZone:'my-dev.com.au',
listenerPort: 443,
publicLoadBalancer: true,
memoryReservationMiB: 8,
cpu: 4096,
desiredCount: 1,
taskImageOptions:{
image: ecs.ContainerImage.fromRegistry('xxx.dkr.ecr.region.amazonaws.com/express-prerender-server'),
containerPort: 3000
},
});
}
}
module.exports = { PrerenderInfrasctutureStack }发布于 2020-05-05 15:54:16
这是因为如果不显式传递群集,那么它将使用帐户上存在的默认群集。但是,默认集群从没有EC2容量开始,因为EC2实例在运行时要花钱。您可以使用空的默认集群和Fargate模式,因为Fargate不需要EC2容量,它只是在Fargate内运行容器,但是默认集群在向集群中添加EC2实例之前不会与EC2模式一起工作。
这里的简单解决方案是改用ApplicationLoadBalancedFargateService,因为Fargate服务使用Fargate容量运行,因此它们不需要集群中的EC2实例。或者,您应该使用以下内容定义自己的集群:
// Create an ECS cluster
const cluster = new ecs.Cluster(this, 'Cluster', {
vpc,
});
// Add capacity to it
cluster.addCapacity('DefaultAutoScalingGroupCapacity', {
instanceType: new ec2.InstanceType("t2.xlarge"),
desiredCapacity: 3,
});然后在创建ApplicationLoadBalancedEc2Service时将该集群作为属性传递
希望这能有所帮助!
https://stackoverflow.com/questions/61607773
复制相似问题