ASG not being scaled by capacity provider in ECS deployment

I am currently in the process of setting up an ECS on EC2 service. My goal is to implement a blue/green deployment strategy where, upon deploying a new version of my application, ECS will momentarily double the number of tasks to accommodate the new version before terminating the old tasks once the new ones are running smoothly.

This method is widely used for deploying applications to ensure minimal downtime for users.

Following recommendations from various AWS blogs, I have utilized a capacity provider in my CDK project. The constructs within my CDK project include:

const autoscalingGroup = new AutoScalingGroup(this, `${this.id}-autoscaling-group`, {
    maxCapacity: 2,
    minCapacity: 1,
    minHealthyPercentage: 100,
    maxHealthyPercentage: 200,
    desiredCapacity: 1,
    ...
})

capacityProvider = new AsgCapacityProvider(this, `${this.id}-capacity-provider`, {
    autoScalingGroup: autoscalingGroup,
    enableManagedScaling: true,
    enableManagedTerminationProtection: true,
})

cluster = new Cluster(this, `${this.id}-ecs-cluster`, {
    ...
})

cluster.addAsgCapacityProvider(capacityProvider)

new Ec2Service(this, `${this.id}-ec2-service`, {
    cluster: ecsCluster,
...
})

The above CDK code effectively sets up two infrastructure components and establishes connections between them.

The first component consists of an ECS cluster and service responsible for initiating new tasks for my application, while the second component is an ASG tasked with launching servers for the application's tasks to run on. (Fargate could potentially eliminate the need for this second layer, but that is not the current focus).

Additionally, a capacity provider is created and assigned to the cluster so that it knows where to locate EC2 instances for its ECS services.

During the initial deployment, everything runs smoothly - ASG initiates a new EC2 instance and ECS launches a task on it.

Issues arise during subsequent deployments. At this stage, one would expect ECS to instruct ASG to scale up by adding another instance to match the new task requirement (each instance in my setup accommodates 1 task). Unfortunately, ECS fails to do so and remains stuck without finding a suitable instance to place a new task.

Answer №1

The issue with the configuration above is that it lacks a crucial element; a connection between the ECS service and the capacity provider:

new Ec2Service(this, `${this.id}-ec2-service`, {
    cluster: ecsCluster,
    taskDefinition: this.props.taskDefinition,
    // It is essential to associate this specific ECS service with the capacity provider.
    // Just linking the cluster does not enable this service to trigger ASG events
    capacityProviderStrategies: [{
        capacityProvider: capacityProvider.capacityProviderName,
        weight: 1,
        base: 1
    }]
})

While granting the cluster access to the capacity provider allows its services to deploy tasks on the instances, it does not permit an individual service to initiate scale up and down actions. To achieve this, you must specify the capacity provider for the ECSService itself by including a capacity provider strategy. Further details on the specific settings for the strategy can be accessed here

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

Leveraging Express Mergeparams in TypeScript

I've run into an issue while working on my small project in Typescript. The problem arises when I attempt to nest my router, as Typescript doesn't seem to acknowledge the parent's parameter. Within the "child" file, I have the following cod ...

"Navigate to another screen with the FlatList component upon press, displaying specific

I've created a flatlist of countries with a search filter using an API. I need help implementing a feature where clicking on a country's name in the list redirects to a screen that displays the country's name and number of cases. The screen ...

Upon transitioning from Angular 5 to Angular 6, a noticeable issue arises: The existing document lacks a required doctype

I recently updated my project from Angular 5 to Angular 6. Post-upgrade, everything compiles without errors. However, when I try to access the website, all I see is a blank screen. Upon inspecting the console, I came across the following error message: Th ...

What is the best way to identify property errors in a React/Typescript project using ESLint?

I'm currently in the process of transitioning a Typescript project created with create-react-app to the latest version. As part of this update, I am moving from tslint to eslint which has posed some challenges. The main issue I'm facing is gettin ...

Commit to choosing an option from a dropdown menu using TypeScript

I just started learning about typescript and I have been trying to create a promise that will select options from a drop down based on text input. However, my current approach doesn't seem to be working as expected: case 'SelectFromList': ...

When attempting to run npm run build for a Next.js application on an EC2 instance, it unexpectedly terminates on its own

While attempting to deploy my Next.js app on EC2, I encountered an issue where the npm run build command was being automatically killed. Suspecting it may be due to insufficient RAM, I switched to an instance type with 4GB of RAM (t3.medium), but the probl ...

Adjusting the array when items in the multi-select dropdown are changed (selected or unselected)

I am looking to create a multi-select dropdown in Angular where the selected values are displayed as chip tags. Users should be able to unselect a value by clicking on the 'X' sign next to the chip tag, removing it from the selection. <searcha ...

What is the procedure for enabling S3 images or objects to be downloaded exclusively through website requests using pre-signed URLs?

I am facing a serious issue with my AWS S3 bucket setup. I have been using the aws-sdk javascript to upload files to the bucket and providing object links for downloading on my Next.js website. However, I recently realized that the bucket permissions are s ...

Trouble Integrating svgr/webpack with Webpack 5 and SingleSpa

I've been grappling with this issue for the past week. Despite scouring through numerous Stack Overflow threads and reading the SVGR/WEBPACK documentation, I haven't been able to find a solution. I decided to upgrade an old React single-spa appl ...

Creating objects based on interfaces

After looking at this straightforward code: interface int1 { aa: string, bb: number, } const obj1:int1 = {} //#1 function fun(param_obj:int1) { //#2 } I am curious as to why the compiler throws an error: Type '{}' is missing the fol ...

Typescript: create a type similar to keyof but with a particular value type

I have an interface called MyInterface interface MyInterface { field1: boolean, field2: MyType, field3: MyType } In this interface, I want to create a new type that contains only the keys which have values of type MyType. While I know about the key ...

Silence in Angular NGRX Effects

I am currently utilizing ngrx Effects to send a http call to my server, but for some reason the effect is not triggered. My goal is to initiate the http call when the component loads. I have tried using store.dispatch in ngOnInit, however, nothing seems to ...

Unable to access data from the Array by passing the index as an argument to the method

Having trouble retrieving an item from an Array using method() with an index argument that returns undefined export class DataService { public list = [ { id: 11, name: 'Mr. Nice' }, { id: 12, name: 'Narco' }, ...

Displaying a dynamic menu using Angular's ngFor loop

I am attempting to create a menu with sub-menus. The desired structure for my menu is outlined below. However, the demo I'm testing is not producing the correct structure. Check out the demo here. "Sub Test": { // Main menu "Example1":"hai",//sub ...

Filtering two distinct arrays in Angular 6 to eliminate duplicate data: A quick guide

array1 = ["one","two"]; array2 = [ {"name":"one","id":101} , {"name":"two","id":102} , {"name":"three","id":103} , {"name":"four","id":104} ]; The data above consists of two arrays: array1 which contains string values, and array2 which contains objects. ...

Developing a custom data structure that identifies the keys of an object with a designated nested attribute

There is an intriguing scenario where dynamically defining types from a centralized JSON data store would prove extremely beneficial. Allow me to elaborate. The JSON file I possess contains a roster of various brands. // brands.json { "Airbus": { ...

The 'asObservable' property is not present on the type '() => any'.ts(2339)

Error: Property 'asObservable' does not exist on type '() => any'.ts(2339) Error: Property 'subscribe' does not exist on type 'Subscription'. Did you mean 'unsubscribe'?ts(2551) Error: Property 'sub ...

Bring in d3 along with d3-force-attract

Recently, I have installed D3 along with d3-force-attract. npm install @types/d3 -S npm install -S d3-force-attract I am currently facing an issue with importing d3 force attract as it is not recognized as a typescript module, unlike d3 itself. The inco ...

An unexpected token was discovered by Jest: export { default as v1 } when using uuid

While working on writing Jest tests for my React component in a Monorepo, I encountered an error while running the Jest test. ● Test suite failed to run Jest encountered an unexpected token... ...SyntaxError: Unexpected token 'export' ...

Deeply nested .map function to update state value

The current state value const [settings, setSettings] = useContext(SettingsContext) Utilizing the .map method on the settings state {settings[categoryIndex]?.config?.map((item: ConfigItem, index: number) => ...