Aws-cdk: JSON path for ContainerOverride in ECS tasks

Created on 26 Jul 2019  Β·  3Comments  Β·  Source: aws/aws-cdk

  • I'm submitting a ...

    • [x] :beetle: bug report
  • What is the current behavior?
    Create a simple Step Function with a Lambda function and a Fargate task:

β”Œβ”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Ξ» │───▢│ Fargate β”‚
β””β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The lambda function produces the following output:

{
  "runId": "123456789"
}

This unique ID needs to be picked up by the Fargate task. This allows us to run several step functions in parallel, re-run them etc. The only way I found to pass an input to en ECS task in step function is the ContainerOverride class with a list of TaskEnvironmentVariable objects. I'd expect to pass the runId like this:

tasks.RunEcsFargateTask(
    cluster=ecs_cluster,
    task_definition=fargate_task_definition,
    assign_public_ip=True,
    container_overrides=[
        targets.ContainerOverride(
            container_name='AnomalyDetectionContainer',
            environment=[
                tasks.TaskEnvironmentVariable(
                    name='RUN_ID',
                    value='$.runId'
                )
            ]
        )
    ]
)

Documentation also mentions valuePath but that does not work (even Pythonic value_path version).

The Fargate task gets RUN_ID environment variable with value $.runId.

  • What is the expected behavior (or behavior of feature suggested)?

The Fargate task gets RUN_ID environment variable with value 123456789.

  • What is the motivation / use case for changing the behavior or adding this feature?
    There seems to be no way to pass an input to ECS tasks in Step Functions. S3 won't work, because we're running several step functions in parallel and the values can't mix up.

  • Please tell us about your environment:

    • CDK CLI Version: 1.2.0
    • Module Version: 1.2.0
    • OS: OSX Mojave
    • Language: Python
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

needs-triage

Most helpful comment

The doc is misleading.
Agree that sfn.Data.string_at('$.runId') is ugly.

All 3 comments

I just learned about the Data class. Here's how it works:

tasks.RunEcsFargateTask(
    cluster=ecs_cluster,
    task_definition=fargate_task_definition,
    assign_public_ip=True,
    container_overrides=[
        targets.ContainerOverride(
            container_name='AnomalyDetectionContainer',
            environment=[
                tasks.TaskEnvironmentVariable(
                    name='RUN_ID',
                    value=sfn.Data.string_at('$.runId')
                )
            ]
        )
    ]
)

I struggled with this, too. It could have been more user-friendly to use valuePath and namePath as suggested in the inline docs:

https://github.com/aws/aws-cdk/blob/06a96adbed3715a285b9af8854a480993361e4df/packages/%40aws-cdk/aws-events-targets/lib/ecs-task-properties.ts#L44-L58

@pepastach so I think this issue should be re-opened.

The doc is misleading.
Agree that sfn.Data.string_at('$.runId') is ugly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schof picture schof  Β·  3Comments

artyom-melnikov picture artyom-melnikov  Β·  3Comments

ababra picture ababra  Β·  3Comments

cybergoof picture cybergoof  Β·  3Comments

abelmokadem picture abelmokadem  Β·  3Comments