Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stepfunctions-tasks: Cannot use JSON path in ContainerOverrides #4078

Closed
aereal opened this issue Sep 14, 2019 · 2 comments
Closed

stepfunctions-tasks: Cannot use JSON path in ContainerOverrides #4078

aereal opened this issue Sep 14, 2019 · 2 comments
Assignees
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container guidance Question that needs advice or information. needs-reproduction This issue needs reproduction.

Comments

@aereal
Copy link

aereal commented Sep 14, 2019

🐛 Bug Report

What is the problem?

EcsRunTaskBase does not generate States[].Parameters of AWS::StepFunctions::StateMachine that refers the execution's input using JSON Path like a $.command properly.
refs. https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html

e.g.:

    const invokeMigrateTask = new Task(this, "InvokeMigrateTask", {
      task: new RunEcsFargateTask({
        containerOverrides: [
          {
            environment: [
              { name: "FETCH_PER_PAGE", value: "$.FetchPerPage" },
            ],
          },
        ],
      }),
    });

expected output:

{
  "StartAt": "InvokeMigrateTask",
  "States": {
    "InvokeMigrateTask": {
      "End": true,
      "Parameters": {
        "Overrides": {
          "ContainerOverrides": [
            {
              "Environment": [
                {
                  "Name": "FETCH_PER_PAGE",
                  "Value.$": "$.FetchPerPage"
                }
              ]
            }
          ]
        },
        "LaunchType": "FARGATE"
      },
      "Type": "Task"
    }
  }
}

but got:

{
  "StartAt": "InvokeMigrateTask",
  "States": {
    "InvokeMigrateTask": {
      "End": true,
      "Parameters": {
        "Overrides": {
          "ContainerOverrides": [
            {
              "Environment": [
                {
                  "Name": "FETCH_PER_PAGE",
                  "Value": "$.FetchPerPage" // Key has no `.$` suffix, so StepFunctions does not treat `"$.FetchPerPage"` as JSON path
                }
              ]
            }
          ]
        },
        "LaunchType": "FARGATE"
      },
      "Type": "Task"
    }
  }
}

Reproduction Steps

  • create a state machine that has the task with input reference using JSON path like above
  • start an execution of the state machine with the parameters
  • can confirm the task was passed the parameter with bare JSON path (is not substituted as expected)

Verbose Log

input:

{
  "FetchPerPage": "250"
}

TaskScheduled event log:

    "Overrides": {
      "ContainerOverrides": [
        {
          "Name": "migrator",
          "Environment": [
            {
              "Name": "FETCH_PER_PAGE.$",
              "Value": "$.FetchPerPage"
            }
          ]
        }
      ]
    },

Environment

  • CDK CLI Version: 1.8.0
  • Module Version: 1.8.0
  • OS: all
  • Language: TypeScript

Other information

Current my workaround:

class MyTask extends RunEcsFargateTask {
  constructor(props: RunEcsFargateTaskProps) {
    super(props);
  }

  public bind(task: Task): StepFunctionsTaskConfig {
    const config = super.bind(task);
    if (
      config.parameters &&
      config.parameters.Overrides &&
      config.parameters.Overrides.ContainerOverrides
    ) {
      config.parameters.Overrides.ContainerOverrides = config.parameters.Overrides.ContainerOverrides.map(
        (override: any) => {
          if (override.Environment) {
            override.Environment.map((env: any) => {
              if ((env.Value as string).startsWith("$.")) {
                env["Value.$"] = env.Value;
                delete env.Value;
              }
              return env;
            });
          }
          return override;
        }
      );
    }
    return config;
  }
}

maybe related: #1480 #2937

@aereal aereal added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 14, 2019
@SomayaB SomayaB added @aws-cdk/aws-ecs Related to Amazon Elastic Container needs-reproduction This issue needs reproduction. labels Sep 16, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 17, 2019

Have you seen this page? https://docs.aws.amazon.com/cdk/api/latest/docs/aws-stepfunctions-readme.html

Have you seen this example?

const fargateTask = new ecs.RunEcsFargateTask({
  cluster,
  taskDefinition,
  containerOverrides: [
    {
      containerName: 'TheContainer',
      environment: [
        {
          name: 'CONTAINER_INPUT',
          value: Data.stringAt('$.valueFromStateData')
        }
      ]
    }
  ]
});

@rix0rrr rix0rrr closed this as completed Sep 17, 2019
@rix0rrr rix0rrr added guidance Question that needs advice or information. and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2019
@aereal
Copy link
Author

aereal commented Sep 17, 2019

Sorry, I missed it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container guidance Question that needs advice or information. needs-reproduction This issue needs reproduction.
Projects
None yet
Development

No branches or pull requests

3 participants