There's a companion blog post that goes along with this repo in case you haven't seen it yet.
This repo contains sample code to spin up an ECS Fargate task definition that can run on-demand via ECS run-task.
Once the container is finished running the code, it will spin back down to zero.
This is great for when you have ad-hoc jobs that need to be run on demand for billing reasons and they will run for longer than the Lambda max timeout.
This example repo shows how to run the deployed task via the AWS CLI; however, you can invoke ecs run-task
in different ways if you prefer such as the AWS Console, EventBridge etc.
The sample script runs the task in the AWS account's default ECS cluster, but you can change the script to have it run in a different cluster.
You will also likely want to change the container image to yours since this example pulls the "hello world" image from DockerHub.
- Install node.js and npm. See
.nvmrc
for the recommended version. - Ensure you have an AWS account, install the AWS CLI, and configure your credentials
- Clone the repo
npm install
npm run deploy
to deploy to your AWS account./scripts/run-task.sh
once deployed to run the task on demand- View logs of task run in the
EcsRunTaskDemoStack-logs
Amazon CloudWatch log group to ensure it ran
To delete the resources created by this project, run npm run destroy
.