Using CDK to Deploy ECS Services

After spending a whole day attempting to deploy ECS using EC2, I am encountering an error that is preventing the task from being placed due to no container instances meeting all the requirements. The reason given is that there are no Container Instances found in the cluster. This issue is outlined further in the Troubleshooting section of the Amazon ECS Developer Guide.

service prod-ecsStack-EC2Service5392EF94-71wVDsfHgsZh was unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster. For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.

I suspect that the CPU and memory allocation in my task definition container are too small. Currently, I am playing it safe with a t2.small instance, but I aim to use the smallest possible instance in the future.

The ECR houses the container repository, and it is constructed using the correct architecture.

This is my current CDK code. Thank you.

const vpc = new ec2.Vpc(this, 'PersonalWebsiteVpc', {
    maxAzs: 2,
});

const cluster = new ecs.Cluster(this, 'PersonalWebsiteCluster', {
    vpc: vpc
});

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
    vpc,
    instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.SMALL),
    machineImage: new ec2.AmazonLinuxImage(),
    minCapacity: 1,
    maxCapacity: 2
});

const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
    autoScalingGroup: autoScalingGroup,
});

cluster.addAsgCapacityProvider(capacityProvider);

const repository = ecr.Repository.fromRepositoryName(this, 'MyRepository', 'my-personal-website-repo');

const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');

const container = taskDefinition.addContainer('web', {
    image: ecs.ContainerImage.fromEcrRepository(repository, 'latest'),
    memoryLimitMiB: 1024,
    cpu: 512,
});

container.addPortMappings({
    containerPort: 80,
    hostPort: 80
});

new ecs.Ec2Service(this, 'EC2Service', {
    cluster,
    taskDefinition,
});

Answer №1

For an EC2 instance to properly function, it is essential to have the ECS agent installed. Opt for using the ecs.EcsOptimizedImage as the value for the machineImage prop instead of a generic AMI.

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

Troubleshooting problem with rxjs subscription impacting component UI refresh

Currently, I am diving deep into the world of rxjs Observables, Observers, and Subscriptions. In order to grasp their functionality better, I decided to experiment with a sample code that updates the UI with random numbers at intervals of 1 second. My ulti ...

Generate a commitment from the function

I know the basics of JavaScript Promise and promise chain, but I'm looking to deepen my understanding. For example, take a look at the method provided below. It's in TypeScript, but can be adjusted for JavaScript ES6. private InsertPersonInDB(p ...

Angular: How can I apply animation to rotate an image within a component?

Within my map application, I have implemented a component called compass component. I am seeking a way to programmatically rotate this compass with animation as the map is rotated. The solution involves utilizing angular animation. To achieve this functio ...

Encountering Compilation Error in @microsoft/mgt Graph Toolkit Upon Transition from Angular 11 to Angular 13

Previously, I had integrated the Microsoft toolkit into my Angular 11 application without any issues. However, when I was asked to upgrade to Angular 13 and updated the toolkit to its latest version (2.3.2 at the time of writing), I started encountering co ...

Modify multiple elements in a nested array by utilizing the $set and $push operators

Here is an example of the Workspace document that needs box positions updated when dragged and dropped on the front end. { "_id": ObjectId("5eaa9b7c87e99ef2430a320b"), "logo": { "url": ".../../../assets/logo/dsdsds.png", "name": "testUpload" }, "n ...

What's the best way to make a toast notification appear when an API call is either successful or encounters

Seeking guidance on incorporating toast messages within an Angular + Ionic 6 application... My goal is to display a toast message in response to events such as clearing a cart or submitting an order, with the message originating from an API call. While a ...

When trying to use TypeScript with next.js, encountering an unexpected token `?` error is not

Having an issue with next.js, the command npm run dev keeps failing due to a syntax error related to an optional property in a tsx file: Syntax error: Unexpected token 44 | 45 | type State<T_HT> = { > 46 | ghostHighlight: ?{ | ...

A glitch was encountered during the execution of the ionic-app-scripts subprocess

I recently started using Ionic 3 and created an application that I'm trying to convert into an APK. To generate a debug (or testing) android-debug.apk file, I used the following CLI command: ionic cordova build android --prod The pages are declared ...

What is the best way to see if a variable is present in TypeScript?

I am facing an issue with my code that involves a looping mechanism. Specifically, I need to initialize a variable called 'one' within the loop. In order to achieve this, I first check if the variable exists and only then proceed to initialize it ...

Encountering an XHR error when using a systemjs module in TypeScript

Error: GET http://localhost:63342/Dog.js 404 (Not Found) XHR error (404 Not Found) loading http://localhost:63342/Dog.js <br/><br/>Below is the script in my index.html file. ...

Incorporating TypeScript basics into the if statement post compiling

As I delve into the Angular2 Quickstart, I stumbled upon a peculiar issue within app.component.js after compiling app.component.ts using tsc (version 1.8.2): if (d = decorators[i]) I am unable to pinpoint where I may have gone wrong in configuring the qu ...

Nestjs Roles Decorator: Unusual behavior in extracting user from payload information

I have been working on implementing my Roles Decorator in Nestjs and it has been going well. However, I encountered an issue when trying to compare the user data from the jwt-token payload to the required role. Strangely, I found that I can only access the ...

Enhancing Pixi.js functionality with TypeScript: Utilizing 'none' Module Settings

My project is a 100% JavaScript application that operates in the browser, consisting of around 20 JS files with all function names in the global scope. Whenever I make changes to a JS file, I can simply refresh the page and see the updates immediately. Ho ...

Is there a way to specialize generic methods in Typescript and make them more specific?

I am working with a generic static method in an abstract class: abstract class Base { static find<T extends Base>(options?: Object): Promise<T[]> { return findResults(options); } } Now, I am trying to specify its type in a derived cla ...

Issue with Vue.js Typescript when setting a debounced function

Upon debouncing a function in my Vue.js application, I encountered the following error message: Type 'DebouncedFunc<(queryParams: QueryParams, page?: number) => Promise<void>>' is not assignable to type '(queryParams: QueryPa ...

Is it possible to utilize ReturnType and Parameters in a generic function declaration on TypeScript?

While attempting to create a generic wrapper function, I initially thought the following code would suffice, but unfortunately, it is not functioning as expected: function wrapFunctionWithLogging<T extends Function>(f: (...args: Parameters<T>) ...

Unable to retrieve component name using React.Children

While working with react in the nextjs framework, I attempted to create my own dropdown component structured as follows: <Dropdown> <DropdownToggle>Action</DropdownToggle> <DropdownMenu> <DropdownItem>Menu 1</Dr ...

Do interfaces in Typescript require nested properties to be mandatory?

My interface contains a nested object: export interface Person { PersonWrapper: { name: string; address: string email?: string; } } When attempting to create an object from this interface, it appears that name is not mandat ...

Differences between `typings install` and `@types` installation

Currently, I am in the process of learning how to integrate Angular into an MVC web server. For guidance, I am referring to this tutorial: After some research and noticing a warning from npm, I learned that typings install is no longer used. Instead, it ...

What steps should I take to resolve the issue of my endpoint failing to accept POST requests?

I am in the process of developing a customized API, with an endpoint that is specified as shown below: https://i.stack.imgur.com/sZTI8.png To handle the functionality for this endpoint, I have set up a Profiling Controller. Inside my controller directory ...