[](https://badge.fury.io/js/cdk-fargate-run-task)
[](https://badge.fury.io/py/cdk-fargate-run-task)
[](https://github.com/pahud/cdk-fargate-run-task/actions/workflows/build.yml)
# cdk-fargate-run-task
Define and run container tasks on AWS Fargate at once or by schedule.
# sample
```python
const app = new cdk.App();
const env = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const stack = new cdk.Stack(app, 'run-task-demo-stack', { env });
// define your task
const task = new ecs.FargateTaskDefinition(stack, 'Task', { cpu: 256, memoryLimitMiB: 512 });
// add contianer into the task
task.addContainer('Ping', {
image: ecs.ContainerImage.fromRegistry('busybox'),
command: [
'sh', '-c',
'ping -c 3 google.com',
],
logging: new ecs.AwsLogDriver({
streamPrefix: 'Ping',
logGroup: new LogGroup(stack, 'LogGroup', {
logGroupName: `${stack.stackName}LogGroup`,
retention: RetentionDays.ONE_DAY,
}),
}),
});
// deploy and run this task once
const runTaskAtOnce = new RunTask(stack, 'RunDemoTaskOnce', { task });
// or run it with schedule(every hour 0min)
new RunTask(stack, 'RunDemoTaskEveryHour', {
task,
cluster: runTaskAtOnce.cluster,
runOnce: false,
schedule: Schedule.cron({ minute: '0' }),
});
```
## Public Subnets only VPC
To run task in public subnets only VPC:
```python
new RunTask(stack, 'RunTask', {
task,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
```
# ECS Anywhere
[Amazon ECS Anywhere](https://aws.amazon.com/ecs/anywhere/) allows you to run ECS tasks on external instances. To run external task once or on schedule:
```python
const externalTask = new ecs.TaskDefinition(stack, 'ExternalTask', {
cpu: '256',
memoryMiB: '512',
compatibility: ecs.Compatibility.EXTERNAL,
});
externalTask.addContainer('ExternalPing', {
image: ecs.ContainerImage.fromRegistry('busybox'),
command: [
'sh', '-c',
'ping -c 3 google.com',
],
logging: new ecs.AwsLogDriver({
streamPrefix: 'Ping',
logGroup: new LogGroup(stack, 'ExternalLogGroup', {
retention: RetentionDays.ONE_DAY,
removalPolicy: cdk.RemovalPolicy.DESTROY,
}),
}),
});
// run it once on external instance
new RunTask(stack, 'RunDemoTaskFromExternal', {
task: externalTask,
cluster: existingCluster,
launchType: LaunchType.EXTERNAL,
});
// run it by schedule on external instance
new RunTask(stack, 'RunDemoTaskFromExternalSchedule', {
task: externalTask,
cluster: existingCluster,
launchType: LaunchType.EXTERNAL,
runAtOnce: false,
schedule: Schedule.cron({ minute: '0' }),
});
```
Please note when you run task in `EXTERNAL` launch type, no fargate tasks will be scheduled. You will be responsible to register the external instances to your ECS cluster. See [Registering an external instance to a cluster](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-anywhere-registration.html) for more details.
Raw data
{
"_id": null,
"home_page": "https://github.com/pahud/cdk-fargate-run-task.git",
"name": "cdk-fargate-run-task",
"maintainer": "",
"docs_url": null,
"requires_python": "~=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Pahud Hsieh<pahudnet@gmail.com>",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/85/11/4ea54dd1ca9ca5dfeb30aa5941f23456a36fd5028dba30492f6987306453/cdk-fargate-run-task-2.0.371.tar.gz",
"platform": null,
"description": "[](https://badge.fury.io/js/cdk-fargate-run-task)\n[](https://badge.fury.io/py/cdk-fargate-run-task)\n[](https://github.com/pahud/cdk-fargate-run-task/actions/workflows/build.yml)\n\n# cdk-fargate-run-task\n\nDefine and run container tasks on AWS Fargate at once or by schedule.\n\n# sample\n\n```python\nconst app = new cdk.App();\n\nconst env = {\n account: process.env.CDK_DEFAULT_ACCOUNT,\n region: process.env.CDK_DEFAULT_REGION,\n};\n\nconst stack = new cdk.Stack(app, 'run-task-demo-stack', { env });\n\n// define your task\nconst task = new ecs.FargateTaskDefinition(stack, 'Task', { cpu: 256, memoryLimitMiB: 512 });\n\n// add contianer into the task\ntask.addContainer('Ping', {\n image: ecs.ContainerImage.fromRegistry('busybox'),\n command: [\n 'sh', '-c',\n 'ping -c 3 google.com',\n ],\n logging: new ecs.AwsLogDriver({\n streamPrefix: 'Ping',\n logGroup: new LogGroup(stack, 'LogGroup', {\n logGroupName: `${stack.stackName}LogGroup`,\n retention: RetentionDays.ONE_DAY,\n }),\n }),\n});\n\n// deploy and run this task once\nconst runTaskAtOnce = new RunTask(stack, 'RunDemoTaskOnce', { task });\n\n// or run it with schedule(every hour 0min)\nnew RunTask(stack, 'RunDemoTaskEveryHour', {\n task,\n cluster: runTaskAtOnce.cluster,\n runOnce: false,\n schedule: Schedule.cron({ minute: '0' }),\n});\n```\n\n## Public Subnets only VPC\n\nTo run task in public subnets only VPC:\n\n```python\nnew RunTask(stack, 'RunTask', {\n task,\n vpcSubnets: {\n subnetType: ec2.SubnetType.PUBLIC,\n },\n```\n\n# ECS Anywhere\n\n[Amazon ECS Anywhere](https://aws.amazon.com/ecs/anywhere/) allows you to run ECS tasks on external instances. To run external task once or on schedule:\n\n```python\nconst externalTask = new ecs.TaskDefinition(stack, 'ExternalTask', {\n cpu: '256',\n memoryMiB: '512',\n compatibility: ecs.Compatibility.EXTERNAL,\n});\n\nexternalTask.addContainer('ExternalPing', {\n image: ecs.ContainerImage.fromRegistry('busybox'),\n command: [\n 'sh', '-c',\n 'ping -c 3 google.com',\n ],\n logging: new ecs.AwsLogDriver({\n streamPrefix: 'Ping',\n logGroup: new LogGroup(stack, 'ExternalLogGroup', {\n retention: RetentionDays.ONE_DAY,\n removalPolicy: cdk.RemovalPolicy.DESTROY,\n }),\n }),\n});\n\n// run it once on external instance\nnew RunTask(stack, 'RunDemoTaskFromExternal', {\n task: externalTask,\n cluster: existingCluster,\n launchType: LaunchType.EXTERNAL,\n});\n\n// run it by schedule on external instance\nnew RunTask(stack, 'RunDemoTaskFromExternalSchedule', {\n task: externalTask,\n cluster: existingCluster,\n launchType: LaunchType.EXTERNAL,\n runAtOnce: false,\n schedule: Schedule.cron({ minute: '0' }),\n});\n```\n\nPlease note when you run task in `EXTERNAL` launch type, no fargate tasks will be scheduled. You will be responsible to register the external instances to your ECS cluster. See [Registering an external instance to a cluster](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-anywhere-registration.html) for more details.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Define and run container tasks on AWS Fargate immediately or with schedule",
"version": "2.0.371",
"project_urls": {
"Homepage": "https://github.com/pahud/cdk-fargate-run-task.git",
"Source": "https://github.com/pahud/cdk-fargate-run-task.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "99ee12fbe92a6f0a40a6fbbd06861cd5d372b7efe1d175bfbe3df42cb631f021",
"md5": "396a430a993f0b19b62105195abfb328",
"sha256": "b26f62f894c97fe8f9b3e512ef799fffdc791ddc6ee6b41d2f9912853c32efeb"
},
"downloads": -1,
"filename": "cdk_fargate_run_task-2.0.371-py3-none-any.whl",
"has_sig": false,
"md5_digest": "396a430a993f0b19b62105195abfb328",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.7",
"size": 42743,
"upload_time": "2023-09-24T00:34:08",
"upload_time_iso_8601": "2023-09-24T00:34:08.432988Z",
"url": "https://files.pythonhosted.org/packages/99/ee/12fbe92a6f0a40a6fbbd06861cd5d372b7efe1d175bfbe3df42cb631f021/cdk_fargate_run_task-2.0.371-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "85114ea54dd1ca9ca5dfeb30aa5941f23456a36fd5028dba30492f6987306453",
"md5": "3359ed116e3581d5772be062c1e052af",
"sha256": "399fd259c4f7cd8faddfed522eb8ecbe0479fada5bfec6d7ef6f4becbf85f15d"
},
"downloads": -1,
"filename": "cdk-fargate-run-task-2.0.371.tar.gz",
"has_sig": false,
"md5_digest": "3359ed116e3581d5772be062c1e052af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.7",
"size": 44193,
"upload_time": "2023-09-24T00:34:10",
"upload_time_iso_8601": "2023-09-24T00:34:10.579158Z",
"url": "https://files.pythonhosted.org/packages/85/11/4ea54dd1ca9ca5dfeb30aa5941f23456a36fd5028dba30492f6987306453/cdk-fargate-run-task-2.0.371.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-24 00:34:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pahud",
"github_project": "cdk-fargate-run-task",
"github_not_found": true,
"lcname": "cdk-fargate-run-task"
}