question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create ECS Service with existing task definition ARN

See original GitHub issue

Reproduction Steps

Now our customers cannot create an ECS service using an existing task definition ARN although we have fromFargateTaskDefinitionARN() and fromEc2TaskDefinitionARN().

Related to https://github.com/aws-samples/aws-cdk-examples/issues/112

Error Log

Environment

  • CLI Version :
  • Framework Version:
  • OS :
  • Language :

Other


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:24
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
cajamescommented, May 29, 2020

For anyone still trying to create a service with a task definition ARN, here’s a temporary workaround. It can be done with “Raw Overrides”. Documented here: https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html

You’ll need to create a service with a temporary task definition (can be done easily with CDK), and then overwrite that Task Definition with a new Task Definition.

Our reasons for using this is similar to @machielg, to mount an EFS volume to a Fargate task, which is not currently supported by CloudFormation.

I found this technique in @michaelmoussa’s example.

So in this case:

fargateService.addPropertyOverride('TaskDefinition', customResourceTaskDefinitionArn);

Here’s a gist showing how to create a Fargate + EFS service currently, adapted from @michaelmoussa’s examples. Hope this can help anyone, while the main issue is being fixed.

https://gist.github.com/cajames/3daec680b1101c8358e2ff30dfadd52a

3reactions
b3n3d1k7commented, Jan 28, 2022

For anyone still trying to create a service with a task definition ARN, here’s a temporary workaround. It can be done with “Raw Overrides”. Documented here: https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html

You’ll need to create a service with a temporary task definition (can be done easily with CDK), and then overwrite that Task Definition with a new Task Definition.

Our reasons for using this is similar to @machielg, to mount an EFS volume to a Fargate task, which is not currently supported by CloudFormation.

I found this technique in @michaelmoussa’s example.

So in this case:

fargateService.addPropertyOverride('TaskDefinition', customResourceTaskDefinitionArn);

Here’s a gist showing how to create a Fargate + EFS service currently, adapted from @michaelmoussa’s examples. Hope this can help anyone, while the main issue is being fixed.

https://gist.github.com/cajames/3daec680b1101c8358e2ff30dfadd52a

Because I just spent a few hours trying to figure out why using addPropertyOverride didn’t work and resulted in strange error messages about invalid parameter types during deployment, maybe this is useful for someone else. Set the task-definition using the member instead of using addPropertyOverride:

# instead of this
(service.service.node.tryFindChild('Service') as CfnService)?.addPropertyOverride(
  'TaskDefinition',
  customTaskDefinition.getResponseField('taskDefinition.taskDefinitionArn'),
);

# use this
(service.service.node.tryFindChild('Service') as CfnService).taskDefinition = customTaskDefinition.getResponseField('taskDefinition.taskDefinitionArn');

Note: Using addPropertyOverride resulted in both, the old and the new task-definition attached to the service in the cloudformation template for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a task definition using the new console
Open the new console at https://console.aws.amazon.com/ecs/v2 . · In the navigation pane, choose Task definitions · Choose Create new task definition, Create new ......
Read more >
update-service — AWS CLI 2.9.9 Command Reference
For services using an external deployment controller, you can update only the desired count, task placement constraints and strategies, health check grace ...
Read more >
clearvoice/aws-ecs - CircleCI Developer Hub
Registers a task definition for the given ECS service and updates the service to use it. Optionally polls the status of the deployment...
Read more >
aws_ecs_task_definition | Resources | hashicorp/aws
task_role_arn - (Optional) ARN of IAM role that allows your Amazon ECS container task to make calls to other AWS services. volume -...
Read more >
aws.ecs.Service - Pulumi
Family and revision ( family:revision ) or full ARN of the task definition that you want to run in your service. Required unless...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found