aws-ecs-patterns error: Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster
aws-ecs-patterns error: Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster
根据 AWS CDK 文档,如果 I declare my VPC then I shouldn't declare 'capacity',希望有人能在这里帮助我,但是当我 运行 cdk synth 时,我收到以下错误。 ..
throw new Error(Validation failed with the following errors:\n ${errorList}
);
Error: Validation failed with the following errors:
[PrerenderInfrasctutureStack/preRenderApp/Service] Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster.
这是我的代码...
(我希望 Nathan Peck 看到这个)
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 }
这是因为如果您没有明确传递集群,那么它会使用您帐户中存在的默认集群。然而,默认集群开始时没有 EC2 容量,因为 EC2 实例在 运行 时会产生费用。您可以将空的默认集群与 Fargate 模式一起使用,因为 Fargate 不需要 EC2 容量,它只是 运行s 您在 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
时将该集群作为 属性 传递
希望对您有所帮助!
根据 AWS CDK 文档,如果 I declare my VPC then I shouldn't declare 'capacity',希望有人能在这里帮助我,但是当我 运行 cdk synth 时,我收到以下错误。 ..
throw new Error(
Validation failed with the following errors:\n ${errorList}
);Error: Validation failed with the following errors: [PrerenderInfrasctutureStack/preRenderApp/Service] Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster.
这是我的代码... (我希望 Nathan Peck 看到这个)
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 }
这是因为如果您没有明确传递集群,那么它会使用您帐户中存在的默认集群。然而,默认集群开始时没有 EC2 容量,因为 EC2 实例在 运行 时会产生费用。您可以将空的默认集群与 Fargate 模式一起使用,因为 Fargate 不需要 EC2 容量,它只是 运行s 您在 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
希望对您有所帮助!