The EC2Service's CapacityProviderStrategies is encountering an issue with the message: "The specified capacity provider named ****** could not be

After reading this resolved article, I decided to set up two AutoScalingGroup, two AsgCapacityProvider, and two ecs on ec2 service

Now, my goal is to attach these CapacityProvider to each service.

However, I encountered an error message stating:

The specified capacity provider myapp-dev-admin-cp was not found

const adminCapacityProvider = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider', {
  autoScalingGroup:adminAutoScalingGroup,
  capacityProviderName: `myapp-${targetEnv}-admin-cp`
});

const adminCapacityProvider2 = new ecs.AsgCapacityProvider(this, 'admin-asg-capacity-provider2', {
  autoScalingGroup:adminAutoScalingGroup2,
  capacityProviderName: `myapp-${targetEnv}-admin-cp2`
});

cluster.addAsgCapacityProvider(adminCapacityProvider);
cluster.addAsgCapacityProvider(adminCapacityProvider2);

const ecsAiService = new ecs.Ec2Service(this, 'AiService', {
  cluster,
  taskDefinition:aiTaskDefinition,
  serviceName: `myapp-${targetEnv}-ai-service`,
  enableExecuteCommand:true,
  securityGroups: [adminServiceSg],
  vpcSubnets:{subnetType: ec2.SubnetType.PUBLIC },
  capacityProviderStrategies:[
    capacityProvider:`myapp-${targetEnv}-admin-cp`// error occurs here
  ]
})

I researched further and discovered that for fargate, the options should be FARGATE or FARGATE_SPOT, but since mine is ECS on EC2, I'm unsure what to use for capacityProviderStrategie's props.

If anyone can offer any assistance, it would be greatly appreciated. Thank you.

Answer №1

One possible reason for this issue could be that the service is being initialized before the capacity provider.

To establish an implicit dependency (and avoid specifying the capacity provider name in multiple places), you can use the following approach:

...
  capacityProviderStrategies:[
    capacityProvider: adminCapacityProvider.capacityProviderName
  ]
...

By doing this, you are informing CDK that your service relies on the capacity provider and should only be created after it has been set up.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Signal a return type error when the provided element label does not correspond with an existing entity

I am working on a component that accepts three props: children (React elements), index, and label. The goal is for the component to return the child element at a specific index when index is passed, and to return the element with a specific label when la ...

Ensuring that the designated key of an object is an extension of Array

What is the best way to ensure that the specified keyof a type extends an array? Consider the following type example: type TestType = { arrayKey: Array<number>, notArrayKey: number } There is also a function that accesses the specified key ...

Encounter the "Error: Source 'cloudsTileLayer-RasterSource' not found" message while trying to integrate a weather tile layer into Azure Maps

I have been working on a React application that utilizes the React-Azure-Maps npm package. My current challenge involves creating a weather layer, which I believe shares similarities with the sample code provided for layers. The code snippet responsible f ...

The VSCode's intellisense for Angular Material fails to function effectively

In the midst of my project on Angular version 13, I have successfully installed Angular Material using the command below: ng add @angular/material The package has been properly included in the node_modules folder. However, when working with TypeScript ...

The function is failing to return the expected value received from the observable subscription

I am attempting to verify the existence of a user in an Angular's in-memory API by validating their username. The function checkUsernameExists(username) is supposed to return an Observable<boolean> based on whether the API responds with undefine ...

Using kdbxweb for generating databases, saving, and accessing passwords to be utilized in scripts and tasks

Struggling to grasp the concepts behind the kdbxweb library, I find myself unable to navigate the documentation due to my lack of prerequisite knowledge. It seems the information provided is geared towards users with a certain level of understanding that I ...

Generate types based on properties of a nested interface dynamically

Consider the setup provided: enum FormGroups { customer = 'customer', address = 'address', } interface Customer { 'firstName': string; } interface Address { 'street': string; } interface SomeFormEvent { ...

Issue: The system needs the 'image' property to proceed (Dall E's image variation API by OpenAI)

Utilizing the Dall E Create image variation API has been a bit challenging for me. Every time I send a post request, I encounter this particular error: error: { "code": null, "message": "'image' is a required property&q ...

Angular Pipe: Working with Data Structures in Angular With Nested Arrays and Objects

After struggling to customize answers for similar questions, I find myself in need of some assistance. My current challenge involves using an angular pipe to filter the following data structure: subjects = [ { name: "subject1", keywords:[& ...

What's the best way to replicate a specific effect across multiple fields using just a single eye button?

Hey everyone, I've been experimenting with creating an eye button effect. I was able to implement one with the following code: const [password, setPassword] = useState('') const [show, setShow] = useState(false) <RecoveryGroup> ...

Using TypeScript with Watermelondb

I'm currently developing a React App and I want to implement Watermelondb for Offline Storage, but I'm unsure about using it with TypeScript. I have already set up the database and created Course and Lesson model files from the Watermelondb libra ...

Warning: Potential spacing issues when dynamically adjusting Material UI Grid using Typescript

When working with Typescript, I encountered an error related to spacing values: TS2322: Type 'number' is not assignable to type 'boolean | 7 | 2 | 10 | 1 | 3 | 4 | 5 | 6 | 8 | "auto" | 9 | 11 | 12'. No lint errors found Version: typesc ...

Stop Node Modules from Referencing Global Location

Recently, I ran into an issue after updating my project from Git. The problem arose when trying to use ngx-material-timepicker in conjunction with the luxon library. (It's important to note that ngx-material-timepicker isn't a new addition to th ...

Using TypeScript, add an observable to an array of observables using RxJS

Can someone explain how to include Observable<News> in an array of observables? newsArray: Observable<Array<any>>; addNews(newsId: number) { let news = this.newsService.getNewNews(newsId); // this results in an Observable<News> ...

The proper approach for managing downloaded d.ts files from DefinitelyTyped after installation through npm

Visual Studio 2017 Enterprise ASP.NET MVC Application TypeScript 2.5 SDK Source control is in TFS I have opted to use Microsoft's built-in property editor instead of creating a custom tsconfig.config file: https://i.sstatic.net/VgcQO.png To streaml ...

Interface displaying auto-detected car types

I have a setup that looks like this: interface ValueAccessor<T> { property: keyof T; getPropertyValue: (value: any) => value; } I am trying to figure out how to define the correct type and replace the any when I want to provide a custom ...

Differences between Typescript static methods and functions defined outside of classesWhen comparing Types

What distinguishes a static class method from a function defined outside a class in TypeScript, especially when visibility is not a concern? While there are differences in visibility from other classes and files, what factors should be considered when dec ...

What is the best way to enhance @Query() dto with unfamiliar properties?

I have successfully created a table with pagination loading similar to the example provided in this tutorial. In my get controller function, I am currently utilizing @Query() pageOptionsDto: PageOptionsDto<PlayerSortColumn> as a parameter. This is t ...

Tips on incorporating jstree into an Angular 2 application with TypeScript and @types/jstree

Hello, I am new to ng2 and have a question that may seem obvious to some. I recently installed the jstree library using npm in my angular-cli application by running the command npm i jstree --save. Following this, I also installed the types for jstree wi ...

Combining pixijs with TypeScript in Ionic 2 using npm

To begin, I ran the command npm install -g ionic Followed by ionic start pixiApp blank --v2 Navigated to the pixiApp directory with cd pixiApp Installed necessary dependencies using npm install Added a specific version of pixi.js (4.1.0) with npm install p ...