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

ec2: cfn-init support in ASGs #1413

Closed
cohalz opened this issue Dec 20, 2018 · 12 comments
Closed

ec2: cfn-init support in ASGs #1413

cohalz opened this issue Dec 20, 2018 · 12 comments
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/large Large work item – several weeks of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. management/tracking Issues that track a subject or multiple issues p1

Comments

@cohalz
Copy link
Contributor

cohalz commented Dec 20, 2018

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.

@eladb eladb changed the title Logical Id: Possible not to add a hash even if it is not at the top level. Logical Id: Possible not to add a hash even if it is not at the top level Dec 20, 2018
@eladb
Copy link
Contributor

eladb commented Dec 20, 2018

To to make sure I understand the problem: asg.autoScalingGroupName is not the logical ID but rather a the actual name of the ASG, resolved only at deploy-time, and that's the reason we are getting the cyclic dependency, correct?

What you could do is simply use asgResource.logicalId instead of asg.autoScalingGroupName:

`/opt/aws/bin/cfn-signal -e $? --stack ${new cdk.AwsStackName()} --resource ${asgResource.logicalId} --region ${new cdk.AwsRegion}`,

As for a longer term solution, I am not sure this is actually a very common need in the general sense, but perhaps we can provide a nice abstract to 'cfn-signal' so you could do something like:

asg.cfnSignal({ options });

And it will return the "correct" cfn-signal command bound to this specific ASG.

@cohalz
Copy link
Contributor Author

cohalz commented Dec 20, 2018

thanks a lot, did the expected behavior with asgResource.logicalId🙇‍♂️

@cohalz cohalz closed this as completed Dec 20, 2018
@eladb
Copy link
Contributor

eladb commented Dec 20, 2018

I will keep this open (and change title) so we can use this as an example for the cfn-init support, okay?

@eladb eladb reopened this Dec 20, 2018
@eladb eladb changed the title Logical Id: Possible not to add a hash even if it is not at the top level ec2: cfn-init support in ASGs Dec 20, 2018
@cohalz
Copy link
Contributor Author

cohalz commented Dec 20, 2018

okay, thanks.

@eladb eladb added enhancement @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud labels Dec 23, 2018
@srchase srchase added feature-request A feature should be added or improved. and removed enhancement labels Jan 3, 2019
@rix0rrr rix0rrr added gap and removed gap labels Jan 4, 2019
@otterley
Copy link
Contributor

otterley commented Jun 3, 2019

Related: #777

@SanderKnape
Copy link

It seems that logicalId is no longer a property for resources. @eladb what is the current method to fetch the logical ID? It need it for the same purpose as the OP.

@eladb
Copy link
Contributor

eladb commented Jul 16, 2019

@SanderKnape
Copy link

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);

@SomayaB SomayaB added management/tracking Issues that track a subject or multiple issues and removed gap labels Sep 24, 2019
@andreclaro
Copy link

Hello, any workaround to make cfn-init (AWS::CloudFormation::Init:) work with CDK?

Is there a way to add the CloudFormation directly when CDK does not support a feature like this?

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 23, 2020

Related to #777

@rix0rrr rix0rrr added the effort/large Large work item – several weeks of effort label Jan 23, 2020
@rix0rrr rix0rrr added the p1 label Aug 12, 2020
@ericzbeard ericzbeard added the feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. label Apr 7, 2021
@felipeloha
Copy link

i tried to use this and got When applying CloudFormationInit, you must also configure signals by supplying 'signals' at instantiation time.

@github-actions
Copy link

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 31, 2022
@github-actions github-actions bot closed this as completed Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/large Large work item – several weeks of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. management/tracking Issues that track a subject or multiple issues p1
Projects
None yet
Development

No branches or pull requests

10 participants