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 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-ecs-standalone-task

v1.1.1

Published

Runs a standalone ECS task and checks it's Cloud Log events

Downloads

20

Readme

aws-ecs-standalone-task

NPM Version NPM Types

Start an ECS Standalone task, wait for it to complete and get it's logs from CloudWatch.

This package mimics the aws ecs run-task aws-cli command and awaits it's execution.

Made for personal use, but if it suites your needs you are welcome to use it.

There is also a Github Action available.

Installation

Install it locally in your project folder:

npm i aws-ecs-standalone-task
# Or Yarn
yarn add aws-ecs-standalone-task
# Or pnpm
pnpm add aws-ecs-standalone-task

Requirements

You need to have an ECS Cluster as well as a task definition created for your task along with container definitions and optionally a log group where it's container writes the log events.

Usage

Import

import { EcsTaskManager, LogReader }  from "aws-ecs-standalone-task';

Prepare credentials

// AWS Credentials
// ecs:RunTask and ecs:DescribeTasks permissions
// optional: logs:GetLogEvents permission for the log-group and log-stream
const awsConfig = {
  region: "us-east-2",
  credentials: {
    accessKeyId: "********************",
    secretAccessKey: "****************************************",
  },
};

Initiate ECS and Logs

// Initiate the ECS task runner
const ecs = new EcsTaskManager(awsConfig, {
  cluster: "ClusterName", // ECS Cluster Name
  taskDefinition: "my-standalone-task-definition", // ECS Task Definition Name
  securityGroups: ["sg-*****************"], // List of security group IDs for your Task's networkConfiguration.awsvpcConfiguration
  subnets: ["subnet-*****************"], // List of Subnet IDs for your Task's networkConfiguration.awsvpcConfiguration
});

// Optional, if your Task logs to CLoudWatch, you need the log reader to check it's logs once it completes
const logs = new LogReader(awsConfig, {
  logGroupName: "/ecs/my-standalone-ecs-task", // Name of the Log Group
  logStreamPrefix: "ecs/my-task-container/", // Log stream prefix, on which the Task ID is added
});

Run

async function runTask() {
  // dispatch the task and wait for it to completes
  // optional: pass interval and iterations, default check each 6 seconds for 20 times or throw an error
  const taskId = await ecs.dispatchAndWait(6000, 20);

  // or, dispatch, receive the taskId without waiting
  const taskId = await ecs.dispatchTask();

  // then, optionally wait for it to complete
  const taskComplete = await this.waitForTaskComplete(taskId); // optional: interval and iterations

  if (!taskComplete) {
    throw new Error("Task completion timeout");
  }

  // fetch and parse the logs
  const log = await logs.parse(taskId);

  if (log.hasErrors) {
    throw new Error("Task Failed");
  }

  console.log("Cloud Logs", log.messages);
}

runTask();

License

MIT