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.

ec2: cfn-init support in ASGs

See original GitHub issue

I want to use the logical ID of the resource created in the construct library. For example, cfn-signal require AutoScalingGroup’s logical id.

I wrote this code.

    const asg = cluster.addDefaultAutoScalingGroupCapacity({
      instanceType: new ec2.InstanceType("t2.xlarge"),
      instanceCount: 1,
    });

    const appLaunchTemplate = new ec2.cloudformation.LaunchTemplateResource(this, 'AppLaunchTemplate', {
      launchTemplateName: "launchtemplatetest",
      launchTemplateData: {
        userData: new cdk.FnBase64([
            `#!/bin/sh`,
            `set -e`,
            `echo ECS_CLUSTER=${cluster.clusterName} >> /etc/ecs/ecs.config`,
            `/opt/aws/bin/cfn-signal -e $? --stack ${new cdk.AwsStackName()} --resource ${asg.autoScalingGroupName} --region ${new cdk.AwsRegion}`,
          ].join('\n')
        ),
      }
    })
    appLaunchTemplate.addDependency(instanceProfile)

    const asgResource = asg.findChild('ASG') as autoscaling.cloudformation.AutoScalingGroupResource

    asgResource.addPropertyDeletionOverride('LaunchConfigurationName')
    asgResource.addPropertyOverride('LaunchTemplate', {
      LaunchTemplateId: appLaunchTemplate.ref,
      Version: '1'
    })

However Circular dependency caused.

    SampleStack failed: ValidationError: Circular dependency between resources: [AppLaunchTemplate, ClusterDefaultAutoScalingGroupLifecycleHookDrainHook4A9A4325, ClusterDefaultAutoScalingGroupASG0F98E147]
Circular dependency between resources: [AppLaunchTemplate, ClusterDefaultAutoScalingGroupLifecycleHookDrainHook4A9A4325, ClusterDefaultAutoScalingGroupASG0F98E147]

This will be solved by specifying a name or not have a hash in construct library.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
SanderKnapecommented, Jul 16, 2019

For future reference, this is how you can get the logical ID for the autoscaling group:

const autoScalingGroupCfn = <CfnAutoScalingGroup> autoscalingGroup.node.tryFindChild('ASG');
console.log(autoScalingGroupCfn.logicalId);
0reactions
github-actions[bot]commented, Aug 31, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cfn-signal - AWS CloudFormation
Description. The cfn-signal helper script signals CloudFormation to indicate whether Amazon EC2 instances have been successfully created or updated.
Read more >
How to use cfn-init to set up EC2 instances with CloudFormation
You can run the cfn-init command if you SSH into the instance too, which makes a quick deploy-try out process. Just right click...
Read more >
6 unknown CloudFormation features you should know about
cfn -init is executed in the user data script and fetches configuration information from your CloudFormation stack. The configuration is attached ...
Read more >
Issue with cfn-signal and auto scaling groups using launch ...
The instance user data invokes cfn-signal after cfn-init has ... Instance in ASG gets brought down (minimum instance in service is 0 in...
Read more >
CloudFormation cfn-init breaking in AWS::EC2 - Stack Overflow
This could be because --resource LaunchTemplate is incorrect. It should the ASG or instance resource that uses the launchtemplate, ...
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