简体   繁体   中英

Overriding command in AWS Fargate task in AWS Step Function

The aim is to have an AWS state machine that runs an AWS Fargate task with a custom command. Per AWS docs , the command in the Docker image of the Fargate task may be overridden by having

"Overrides": {
    "ContainerOverrides": [{
        "Name": "container-name",
        "Command.$": "$.commands"
    }]
}

as one item of "Parameters" . Note the .$ after Command .

I want to build the state machine with AWS CDK. Per CDK Docs , I can pass a container override, see parameter container_overrides , which expects a sequence of values of type ContainerOverride as value. In one such ContainerOverride I can specify the command to executed. When I do that, I end up getting

"Overrides": {
    "ContainerOverrides": [{
        "Name": "container-name",
        "Command": ["$.commands"]
    }]
}

as one item of "Parameters" . The key of the command item should include .$ and the value shouldn't be a list.

My question is: how to parameterize aws_cdk.aws_stepfunctions_tasks.EcsRunTask such that the desired "Parameters" item is obtained.

Answering my own question based on this information.

Consider the objective to use AWS CDK to pass the items of the value of {"command": ["arg1", "arg2"]} as command line arguments to a Fargate task inside a step function task. This may be achieved as follows:

from aws_cdk import aws_stepfunctions, aws_stepfunctions_task

aws_stepfunctions_tasks.EcsRunTask(
    ...,
    container_overrides=[
        aws_stepfunctions_tasks.ContainerOverride(
           container_definition=aws_stepfunctions.StateMachine(...),
           command=aws_stepfunctions.JsonPath.list_at("$.command")
        )
    ],
    ...
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM