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

ecs: create Ec2Service or FargateService with imported TaskDefinition #7863

Open
2 tasks
pahud opened this issue May 8, 2020 · 5 comments
Open
2 tasks

ecs: create Ec2Service or FargateService with imported TaskDefinition #7863

pahud opened this issue May 8, 2020 · 5 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container effort/medium Medium work item – several days of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p1

Comments

@pahud
Copy link
Contributor

pahud commented May 8, 2020

FargateService requires the TaskDefinition type and using existing task definition is not allowed.

readonly taskDefinition: TaskDefinition;

Use Case

Becasue cloudformation is missing some features such as TaskDefinition with EFS support, we may create our own task definition with CLI or console and allow CDK to create Fargate service by importing the existing task definition.

Proposed Solution

Maybe we can simply use ITaskDefinition instead?

The drawback is we will not be able to check the defaultContainer here.

if (!props.taskDefinition.defaultContainer) {
throw new Error('A TaskDefinition must have at least one essential container');
}

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@pahud pahud added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels May 8, 2020
@pahud
Copy link
Contributor Author

pahud commented May 8, 2020

related to #6240

@SomayaB SomayaB added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label May 11, 2020
@SoManyHs SoManyHs added p1 and removed needs-triage This issue or PR still needs to be triaged. labels May 18, 2020
@kennu
Copy link

kennu commented Jun 17, 2020

I also need this feature, to be able to define the TaskDefinition externally to support EFS volumes for Fargate.

@mittalyashu
Copy link

This will help me to use CDK to provision the infra and use Github Actions with amazon-ecs-deploy-task-definition for automated deployments.

@madeline-k
Copy link
Contributor

Looks like the PR to fix this went stale. If anyone is interested to revive it, you are welcome to 😄

@madeline-k madeline-k changed the title allow to create FargateService with imported TaskDefinition feat(ecs): create Ec2Service or FargateService with imported TaskDefinition Jan 25, 2023
@pahud pahud changed the title feat(ecs): create Ec2Service or FargateService with imported TaskDefinition ecs: create Ec2Service or FargateService with imported TaskDefinition May 19, 2023
@vcatalano
Copy link

I am still running into this issue and it would be great if we we could resolve it without having to do much hacking. The following is the workaround that I'm current using, it's a modified hack from #25777.

const defaultTaskDefinition = new FargateTaskDefinition(this, 'DefaultTask', {
  family: 'DefaultTask',
  taskRole: taskRole,
  executionRole: taskExecutionRole,
});
defaultTaskDefinition.addContainer(`${serviceName}Container`, {
  containerName: 'DefaultContainer',
  image: ContainerImage.fromRegistry('registry.hub.docker.com/ealen/echo-server'),
});

const myService = new FargateService(this, 'MyService', {
  cluster: this.cluster,
  taskDefinition: defaultTaskDefinition,
  desiredCount: 1,
  securityGroups: [securityGroup],
  serviceName: 'MyService',
  assignPublicIp: false
});

// Lookup the FargateTaskDefinition from the ARN and override the service defnition
const existingTaskDefinition = FargateTaskDefinition.fromFargateTaskDefinitionArn(this, 'ExistingTaskDefinition', 'Existing Task ARN');

(myService.node.tryFindChild('Service') as CfnService).taskDefinition =
  existingTaskDefinition.taskDefinitionArn;

It seems that the bigger issue is that CDK does not allow us to make updates to the FargateService without reverting the task definition to the initial task definition defined by the FargateService construct.

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 effort/medium Medium work item – several days of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants