Interface GuScheduledEcsTaskProps

Configuration options for the [[GuEcsTask]] pattern.

Note it is recommended to use GuVpc.subnetsFromParameterFixedNumber for the subnets prop rather than GuVpc.subnetsFromParameter, as using the latter can result a custom resource being required

See [[ContainerConfiguration]] for details of how to configure the container used to run the task.

taskTimeoutInMinutes does what is says on the tin. The default timeout is 15 minutes.

The taskCommand prop allows you to specify a command to run when the task starts (this can also be done via a CMD statement in your Dockerfile). For example:

const props = { //other props taskCommand: `aws s3 cp s3://${distbucket}/${stack}/${stage}/${app}/task.sh . && ./task.sh }

It is advisable to configure alarms for when the job fails/times out. To do this specify the alarmSnsTopicArn prop.

customTaskPolicies allows your task to interact with other AWS services. By default a task will have read access to the distribution bucket for your account.

You can specify security groups to apply to task using the securityGroups prop.

You can also set the memory and cpu units for your task. See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#task_size for further details.

If you want to pass input from the step function into your EcsTask you can do so via the environmentOverrides prop, which allows you to wire up step function input JSON to environment variables set on the container. For example, const props = { ...otherProps environmentOverrides: [ { name: "VERSION", value: JsonPath.stringAt("$.version"), }, } With the above override, your task will attempt to find a version property in the JSON input passed to the step function, and apply it to the VERSION environment variable. Alternatively, you could hard code a value for the variable in CDK. See https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html for further detail and other override options - this construct currently only supports environment variables.

interface GuScheduledEcsTaskProps {
    app: string;
    assignPublicIp?: boolean;
    containerConfiguration: ContainerConfiguration;
    containerInsights?: boolean;
    cpu?: number;
    customTaskPolicies?: PolicyStatement[];
    enableDistributablePolicy?: boolean;
    environmentOverrides?: TaskEnvironmentVariable[];
    memory?: number;
    monitoringConfiguration: NoMonitoring | GuEcsTaskMonitoringProps;
    schedule: Schedule;
    securityGroups?: ISecurityGroup[];
    storage?: number;
    subnets: ISubnet[];
    taskCommand?: string;
    taskTimeoutInMinutes?: number;
    vpc: IVpc;
}

Hierarchy (View Summary)

Properties

app: string
assignPublicIp?: boolean
containerConfiguration: ContainerConfiguration
containerInsights?: boolean

If true, CloudWatch Container Insights will be enabled for the cluster

false
cpu?: number
customTaskPolicies?: PolicyStatement[]
enableDistributablePolicy?: boolean

Whether to give the task IAM role access to the account's dist bucket. This is enabled by default to avoid breaking changes, but consumers of this pattern that pull a container image that doesn't need extra dependencies from S3 shoud set this value to false.

environmentOverrides?: TaskEnvironmentVariable[]
memory?: number
monitoringConfiguration: NoMonitoring | GuEcsTaskMonitoringProps
schedule: Schedule

Schedule for the task.

E.g.:

  • Schedule.expression("cron(0 8 ? * MON-FRI *)")
  • Schedule.rate(Duration.minutes(5))
securityGroups?: ISecurityGroup[]
storage?: number
subnets: ISubnet[]
taskCommand?: string
taskTimeoutInMinutes?: number
vpc: IVpc