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] Escape hatches do not work for FargateService #10666

Closed
justin8 opened this issue Oct 3, 2020 · 4 comments
Closed

[ecs] Escape hatches do not work for FargateService #10666

justin8 opened this issue Oct 3, 2020 · 4 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. effort/small Small work item – less than a day of effort needs-reproduction This issue needs reproduction. p2

Comments

@justin8
Copy link
Contributor

justin8 commented Oct 3, 2020

When attempting to override any property of the underlying CfnResource it appears that .node.defaultChild is always undefined.

Reproduction Steps

const service = new ecs.FargateService(...)
const cfnService = service.node.defaultChild as ecs.CfnService;
cfnService.addPropertyDeletionOverride("LaunchType");

What did you expect to happen?

To be able to override properties

What actually happened?

$ cdk synth
...
Cannot read property 'addPropertyDeletionOverride' of undefined

Environment

  • CLI Version : 1.66
  • Framework Version: 1.66
  • Node.js Version: v14.8.0
  • OS : Linux
  • Language (Version): TypeScript (3.8.3)

Other


This is 🐛 Bug Report

@justin8 justin8 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2020
@SomayaB SomayaB added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Oct 6, 2020
@SoManyHs SoManyHs added the needs-reproduction This issue needs reproduction. label Nov 16, 2020
@MrArnoldPalmer MrArnoldPalmer added effort/small Small work item – less than a day of effort guidance Question that needs advice or information. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 7, 2020
@SomayaB SomayaB removed the guidance Question that needs advice or information. label Dec 17, 2020
@Ancient87
Copy link

Ancient87 commented Jan 4, 2021

@justin8
I came across this issue myself today. While it seems it's still not fixed yet I did find a workaround and I wanted to share what I found for the next person who ends up here looking for a solution.

If you dig into the code of CDK you find out what defaultChild actually does. It will find a child node named either "Resource" or "Default" in the construct. However, unfortunately, the FargateService doesn't have such a resource and thus it fails.

The workaround is to make use of the children() accessor method which returns an array of all children of the node. In this case there is only a single one (and arguably should be made the default) of type CfnService. This is also the one you want if you want to make changes to the construct's underlying Cfn resource.

I was able to use the following code to add the "FARGATE_SPOT" capacity provider to an "ApplicationLoadBalancedFargateService"

const serviceConstruct: ecs.FargateService = this.service.service;
const scn: cdk.ConstructNode = serviceConstruct.node;
const theFirst: ecs.CfnService = scn.children[0] as ecs.CfnService;
const strategy = [{capacityProvider: "FARGATE_SPOT", weight:1}];
theFirst.addPropertyOverride("capacityProviderStrategy", strategy);

Hope it helps.

@SoManyHs
Copy link
Contributor

Closing this as a duplicate of #14665 -- we'll track this issue there!

@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.

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 bug This issue is a bug. effort/small Small work item – less than a day of effort needs-reproduction This issue needs reproduction. p2
Projects
None yet
Development

No branches or pull requests

6 participants