npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@onivoro/server-aws-ecs

v24.33.9

Published

AWS ECS integration for NestJS applications with task execution capabilities.

Downloads

571

Readme

@onivoro/server-aws-ecs

AWS ECS integration for NestJS applications with task execution capabilities.

Installation

npm install @onivoro/server-aws-ecs

Overview

This library provides a simple ECS (Elastic Container Service) integration for NestJS applications, allowing you to run ECS tasks programmatically.

Module Setup

import { Module } from '@nestjs/common';
import { ServerAwsEcsModule } from '@onivoro/server-aws-ecs';

@Module({
  imports: [
    ServerAwsEcsModule.configure()
  ]
})
export class AppModule {}

Configuration

The module uses environment-based configuration:

export class ServerAwsEcsConfig {
  AWS_REGION: string;
  AWS_PROFILE?: string;  // Optional AWS profile
}

Service

EcsService

The main service for running ECS tasks.

import { Injectable } from '@nestjs/common';
import { EcsService } from '@onivoro/server-aws-ecs';
import { RunTaskCommandInput } from '@aws-sdk/client-ecs';

@Injectable()
export class TaskRunnerService {
  constructor(private readonly ecsService: EcsService) {}

  async runDataProcessingTask() {
    const params: RunTaskCommandInput = {
      cluster: 'my-cluster',
      taskDefinition: 'my-task-definition:1',
      launchType: 'FARGATE',
      networkConfiguration: {
        awsvpcConfiguration: {
          subnets: ['subnet-12345'],
          securityGroups: ['sg-12345'],
          assignPublicIp: 'ENABLED'
        }
      },
      overrides: {
        containerOverrides: [{
          name: 'my-container',
          environment: [
            { name: 'ENV_VAR', value: 'value' }
          ]
        }]
      }
    };

    const result = await this.ecsService.runTasks(params);
    return result;
  }
}

Utility Function

mapObjectToEcsEnvironmentArray

A static utility function to convert a plain object to ECS environment variable format:

import { EcsService } from '@onivoro/server-aws-ecs';

const envVars = {
  NODE_ENV: 'production',
  API_KEY: 'secret-key',
  PORT: '3000'
};

const ecsEnvironment = EcsService.mapObjectToEcsEnvironmentArray(envVars);
// Returns:
// [
//   { name: 'NODE_ENV', value: 'production' },
//   { name: 'API_KEY', value: 'secret-key' },
//   { name: 'PORT', value: '3000' }
// ]

// Use in task configuration
const taskParams: RunTaskCommandInput = {
  cluster: 'my-cluster',
  taskDefinition: 'my-task',
  overrides: {
    containerOverrides: [{
      name: 'container',
      environment: ecsEnvironment
    }]
  }
};

Direct Client Access

The service exposes the underlying ECS client for advanced operations:

@Injectable()
export class AdvancedEcsService {
  constructor(private readonly ecsService: EcsService) {}

  async describeCluster(clusterName: string) {
    const command = new DescribeClustersCommand({
      clusters: [clusterName]
    });
    
    return await this.ecsService.ecsClient.send(command);
  }

  async listTasks(cluster: string) {
    const command = new ListTasksCommand({
      cluster,
      desiredStatus: 'RUNNING'
    });
    
    return await this.ecsService.ecsClient.send(command);
  }
}

Complete Example

import { Module, Injectable } from '@nestjs/common';
import { ServerAwsEcsModule, EcsService } from '@onivoro/server-aws-ecs';
import { RunTaskCommandInput } from '@aws-sdk/client-ecs';

@Module({
  imports: [ServerAwsEcsModule.configure()],
  providers: [BatchProcessorService],
  exports: [BatchProcessorService]
})
export class BatchModule {}

@Injectable()
export class BatchProcessorService {
  constructor(private readonly ecsService: EcsService) {}

  async processBatch(batchId: string, items: string[]) {
    // Convert environment variables
    const environment = EcsService.mapObjectToEcsEnvironmentArray({
      BATCH_ID: batchId,
      ITEMS: items.join(','),
      PROCESS_DATE: new Date().toISOString()
    });

    // Configure task
    const params: RunTaskCommandInput = {
      cluster: 'batch-processing-cluster',
      taskDefinition: 'batch-processor:latest',
      launchType: 'FARGATE',
      count: 1,
      networkConfiguration: {
        awsvpcConfiguration: {
          subnets: [process.env.SUBNET_ID],
          securityGroups: [process.env.SECURITY_GROUP_ID],
          assignPublicIp: 'ENABLED'
        }
      },
      overrides: {
        containerOverrides: [{
          name: 'processor',
          environment
        }]
      }
    };

    // Run task
    const result = await this.ecsService.runTasks(params);
    
    if (result.failures && result.failures.length > 0) {
      throw new Error(`Failed to start task: ${result.failures[0].reason}`);
    }

    return result.tasks?.[0]?.taskArn;
  }
}

Environment Variables

Configure the module using these environment variables:

# Required: AWS region
AWS_REGION=us-east-1

# Optional: AWS profile
AWS_PROFILE=my-profile

AWS Credentials

The module uses the standard AWS SDK credential chain:

  1. Environment variables
  2. Shared credentials file
  3. IAM roles (for EC2/ECS/Lambda)

Limitations

  • This is a thin wrapper around the AWS ECS SDK
  • Only provides the runTasks method for task execution
  • For more advanced ECS operations, use the exposed ecsClient directly

License

MIT