EcsRunTask not deploy any task #22030
-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 17 replies
-
EcsRunTask is actually a task state. I believe you need define a state machine with definition to invoke it. |
Beta Was this translation helpful? Give feedback.
-
@Fitmavincent check out my full sample here import {
App, Stack, StackProps, Duration,
aws_ecs as ecs,
aws_ec2 as ec2,
aws_stepfunctions as sfn,
aws_stepfunctions_tasks as tasks,
} from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class Demo extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {
isDefault: true,
});
const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc });
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TD', {
cpu: 256,
memoryLimitMiB: 512,
});
taskDefinition.addContainer('TheContainer', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/docker/library/busybox:unstable-uclibc'),
memoryLimitMiB: 256,
command: ['sh', '-c', 'ping google.com -c 2'],
logging: new ecs.AwsLogDriver({
streamPrefix: 'demo',
}),
});
const runTask = new tasks.EcsRunTask(this, 'Run', {
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
cluster,
taskDefinition,
assignPublicIp: true,
launchTarget: new tasks.EcsFargateLaunchTarget(),
});
const startState = new sfn.Pass(this, 'StartState');
const definition = startState
.next(runTask);
new sfn.StateMachine(this, 'StateMachine', {
definition,
timeout: Duration.minutes(5),
});
}
}
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
// define resources here...
}
}
// for development, use account/region from cdk cli
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const app = new App();
const stack = new MyStack(app, 'gitpod-workspace-dev', { env: devEnv });
new Demo(stack, 'Demo');
// new MyStack(app, 'gitpod-workspace-prod', { env: prodEnv });
app.synth(); This CDK app creates a step function state machine that invokes a ecs task on Fargate with a container running "ping -c 3 google.com" When I deploy it with Hope this sample helps. |
Beta Was this translation helpful? Give feedback.
-
Hi @Fitmavincent would you please click the "Mark as answer" button to help us better track the activities? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
-
Hi @pahud, I am curious about your repo: https://github.com/pahud/cdk-fargate-run-task/, since it's no longer found. Thanks in advance |
Beta Was this translation helpful? Give feedback.
@Fitmavincent check out my full sample here