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

(aws-ecs-patterns): Cannot read property 'node' of undefined #14324

Closed
tai-acall opened this issue Apr 22, 2021 · 5 comments
Closed

(aws-ecs-patterns): Cannot read property 'node' of undefined #14324

tai-acall opened this issue Apr 22, 2021 · 5 comments
Assignees
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@tai-acall
Copy link

Try to integrate aws-ecs-patterns module and class CfnCodeDeployBlueGreenHook, stuck in logicalId of target property.

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.CfnCodeDeployBlueGreenHook.html

Reproduction Steps

new cdk.CfnCodeDeployBlueGreenHook(this, 'CfnCodeDeployBlueGreenHook', {
      serviceRole: this.getLogicalId(bgDeployRole.node.defaultChild as iam.CfnRole),
      trafficRoutingConfig: {
        type: cdk.CfnTrafficRoutingType.TIME_BASED_CANARY,
        timeBasedCanary: {
            stepPercentage: 50,
            bakeTimeMins: 1
        }
    },
      applications: [
        {
            target: {
                type: 'AWS::ECS::Service',
                logicalId: this.getLogicalId(this.loadBalancedFargateService.service.node.defaultChild as ecs.CfnService),
            },

What did you expect to happen?

class FargateService has node property so any error shouldn't happen.

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecs.FargateService.html

What actually happened?

$ cdk bootstrap
TypeError: Cannot read property 'node' of undefined

Environment

  • CDK CLI Version : 1.100.0 (build d996c6d)
  • Framework Version:
  • Node.js Version:
  • OS :
  • Language (Version):TypeScript (4.2.4)

Other


This is 🐛 Bug Report

@tai-acall tai-acall added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 22, 2021
@peterwoodworth peterwoodworth added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Apr 22, 2021
@SoManyHs
Copy link
Contributor

Hi @tai-acall,
Is bgDeployRole defined in this stack? I see that node is being called on that as well, so wanted to double check where the error was being thrown.

@SoManyHs SoManyHs added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 22, 2021
@tai-acall
Copy link
Author

tai-acall commented Apr 23, 2021

Hello @SoManyHs ,

yes, the bgDeployRole is defined in the same stack as following.

thanks for your time.

    //BlueGreen Deployment
    const bgDeployRole = new iam.Role(this, 'bgDeplyRole', {
      assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com'),
    })
    bgDeployRole.addToPolicy(
      new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        resources: ['*'],
        actions: [
          'codedeploy:CreateApplication',
          'codedeploy:CreateDeployment',
          'codedeploy:CreateDeploymentGroup',
          'codedeploy:GetApplication',
          'codedeploy:GetDeployment',
          'codedeploy:GetDeploymentGroup',
          'codedeploy:ListApplications',
          'codedeploy:ListDeploymentGroups',
          'codedeploy:ListDeployments',
          'codedeploy:StopDeployment',
          'codedeploy:GetDeploymentTarget',
          'codedeploy:ListDeploymentTargets',
          'codedeploy:GetDeploymentConfig',
          'codedeploy:GetApplicationRevision',
          'codedeploy:RegisterApplicationRevision',
          'codedeploy:BatchGetApplicationRevisions',
          'codedeploy:BatchGetDeploymentGroups',
          'codedeploy:BatchGetDeployments',
          'codedeploy:BatchGetApplications',
          'codedeploy:ListApplicationRevisions',
          'codedeploy:ListDeploymentConfigs',
          'codedeploy:ContinueDeployment',
          'sns:ListTopics',
          'cloudwatch:DescribeAlarms',
          'lambda:ListFunctions'
        ]
      })
    );
    bgDeployRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonECS_FullAccess'));

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 23, 2021
@peterwoodworth
Copy link
Contributor

@tai-acall the root cause of the issue is that the class FargateService doesn't have a default child. (This is a bug, so the way you did it should work). The error saying that property "node" of undefined certainly isn't very helpful here either.

Something that might work for ya is using the findChild method, as the class does have children.

target: {
    type: 'AWS::ECS::Service',
    logicalId: this.getLogicalId(loadBalancedFargateService.service.node.findChild('Service') as CfnService),
},

@tai-acall
Copy link
Author

Hi @peterwoodworth , I confirm the findChild method resolve this issue, thanks a lot.

@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-patterns Related to ecs-patterns library guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

5 participants