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): EcsRunTask containerOverrides throws if container name doesn't match construct ID #15171

Closed
Cruaier opened this issue Jun 17, 2021 · 3 comments · Fixed by #15190
Assignees
Labels
@aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@Cruaier
Copy link
Contributor

Cruaier commented Jun 17, 2021

I ran into an issue while updating CDK from 1.77.0 to1.109.0. I create a step function which utilizes ECS tasks (Fargate) to run a long-running task. It uses EcsRunTask from the @aws-cdk/aws-stepfunctions-tasks library.

Reproduction Steps

const vpc = new ec2.Vpc(this, 'VPC');
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDefinition', {
  cpu: 1024,
  memoryLimitMiB: 8192,
});
const containerDefinition = taskDefinition.addContainer('TaskContainer', {
  image: ecs.ContainerImage.fromDockerImageAsset(new ecrassets.DockerImageAsset(this, 'asset', { directory: path.join(__dirname, './image-asset') })),
  containerName: 'AnyOtherNameThatIsNotTheConstructId',
  environment: {
    EVENT: '',
  },
});
new sfntasks.EcsRunTask(this, 'ECSTaskRun', {
  cluster: new ecs.Cluster(this, 'Cluster', { vpc }),
  launchTarget: new sfntasks.EcsFargateLaunchTarget(),
  taskDefinition: taskDefinition,
  assignPublicIp: true,
  containerOverrides: [
    {
      containerDefinition: containerDefinition,
      environment: [{ name: 'EVENT', value: 'something' }],
    },
  ],
  integrationPattern: sfn.IntegrationPattern.RUN_JOB,
  resultPath: sfn.JsonPath.DISCARD,
});

What did you expect to happen?

No error, since the container definition defined in the override is directly returned from the call to TaskDefinition.addContainer, implying that the container does in fact exist in the task definition.

What actually happened?

Error: Overrides mention container with name 'XXX', but no such container in task definition

Environment

  • Framework Version: 1.109.0
  • Node.js Version: v14.16.1

Other

Error is coming from the code in cdk\node_modules\@aws-cdk\aws-stepfunctions-tasks\lib\ecs\run-task.js line 141 were it takes the name of the container (as defined in the overriding option) and looks for it (as a key) in the task definition (with the function tryFindChild:

            const name = override.containerDefinition.containerName;
            if (!cdk.Token.isUnresolved(name)) {
                const cont = this.props.taskDefinition.node.tryFindChild(name);
                if (!cont) {
                    throw new Error(`Overrides mention container with name '${name}', but no such container in task definition`);
                }
            }

This is 🐛 Bug Report

@Cruaier Cruaier added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 17, 2021
@BenChaimberg BenChaimberg added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jun 17, 2021
@BenChaimberg
Copy link
Contributor

Workaround before a fix can be made: set the construct ID and the container name to be the same value:

const containerName = 'TaskContainer';
const containerDefinition = taskDefinition.addContainer(containerName, {
  containerName: containerName,
  // ...
});

@BenChaimberg BenChaimberg removed their assignment Jun 17, 2021
@BenChaimberg
Copy link
Contributor

@Cruaier please feel free to assign me to a fix PR if you happen to work on one. The proper solution is probably to just expose ecs.TaskDefinition.findContainer as public and use that instead of inspecting the construct tree as we do currently. But happy to discuss different options!

Cruaier pushed a commit to Cruaier/aws-cdk that referenced this issue Jun 18, 2021
…Container to check for container in TaskDefinition
@BenChaimberg BenChaimberg changed the title @aws-cdk/aws-stepfunctions-tasks: EcsRunTask - containerOverrides throws wrong error (stepfunctions-tasks): EcsRunTask containerOverrides throws if container name doesn't match construct ID Jun 18, 2021
Cruaier pushed a commit to Cruaier/aws-cdk that referenced this issue Jun 24, 2021
@mergify mergify bot closed this as completed in #15190 Jun 24, 2021
mergify bot pushed a commit that referenced this issue Jun 24, 2021
…tainer name doesn't match construct ID (#15190)

 EcsRunTask, container override is now using using method `findContainer` to check for container in TaskDefinition

fixes #15171 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
…tainer name doesn't match construct ID (aws#15190)

 EcsRunTask, container override is now using using method `findContainer` to check for container in TaskDefinition

fixes aws#15171 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions-tasks bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
2 participants