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

Add support for AWS::CloudFormation::Init #777

Closed
taichi opened this issue Sep 26, 2018 · 17 comments
Closed

Add support for AWS::CloudFormation::Init #777

taichi opened this issue Sep 26, 2018 · 17 comments
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/large Large work item – several weeks of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p1

Comments

@taichi
Copy link
Contributor

taichi commented Sep 26, 2018

TypeScript CDK 0.9.2

How to write AWS::CloudFormation::Init metadata with AWS Construct Library for cfn-init ?
I want to add AWS::CloudFormation::Init metadata to AutoScalingGroup.

@rix0rrr rix0rrr changed the title How to write AWS::CloudFormation::Init Add support for AWS::CloudFormation::Init Sep 26, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Sep 26, 2018

We don't have this modeled as an L2 right now.

You can instantiate a cdk.Resource and pass in the properties that make up an Init resource, and add the appropriate call to the ASGs userData yourself.

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 9, 2018

It should include support for environment variables, by writing them to a script in /etc/profile.d.

Need to do research to see if all ways of starting a program source the files there well enough.

@taichi
Copy link
Contributor Author

taichi commented Oct 9, 2018

I'm trying to convert this template with cdk.
atlassian-aws-deployment / templates / JiraDataCenter.template.yaml

environment variables are in l.1008

@0xdevalias
Copy link
Contributor

0xdevalias commented Nov 6, 2018

Any updates/likely merge time on #792 , or at least a worked example of how to add AWS::CloudFormation::Init to an autoscaling.AutoScalingGroup?

The following template shows that it should be added to the AWS::AutoScaling::LaunchConfiguration in the CloudFormation:

I see that #606 makes reference to being able to find/modify children since 0.10.0. Following the syntax there.. it looks like the following should work for us..:

// Ref: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-init.html
// Ref: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/example-templates-autoscaling.html
const asgLaunchConfig = asg.findChild('LaunchConfig') as autoscaling.cloudformation.LaunchConfigurationResource;
asgLaunchConfig.addOverride("Metadata", {
    "AWS::CloudFormation::Init": {
        "FOO": "BAR",
    }
});

Running cdk synth, I get the following, which implies it is working as expected:

AutoScalingGroupLaunchConfigDEEB160C:
  Type: 'AWS::AutoScaling::LaunchConfiguration'
  ..snip..
  Metadata:
      'AWS::CloudFormation::Init':
          FOO: BAR

@rix0rrr rix0rrr added feature-request A feature should be added or improved. and removed feature-request A feature should be added or improved. feature labels Nov 6, 2018
@eladb
Copy link
Contributor

eladb commented Dec 19, 2018

Closed PR for now. Reopen as needed.

@0xdevalias
Copy link
Contributor

Sad that that PR didn’t land.. :(

@eladb
Copy link
Contributor

eladb commented Dec 20, 2018

We'll get there. It's an important feature... Just got too much on our table RN...
Happy to take contributions of course if you are interested to pick it up

@eladb
Copy link
Contributor

eladb commented Oct 2, 2019

Still relevant

@brettswift
Copy link

brettswift commented Oct 7, 2019

I haven't taken a stab at an L2 construct, but I put together a template I might be able to refactor out into something easier. I needed a shell script to be put onto the machine and be executed. The construct for Init will hopefully make it easier to "just execute this script at launch time". So I have scoped my solution to just the file / command resources, and a little bit of a fairly robust userdata script (that requires the ASG and Launch config for both cfn-init and cfn-signal).

I put it up on a gist instead of here. Hopefully this is helpful if someone writes the L2, to see how I tackled this use case. I'd like to spend time on an L2 but not sure I'll have the time for a while.

https://gist.github.com/brettswift/6e48a70d808a28614438520682459f0c

@brettswift
Copy link

I updated the gist above adding in a builder class to help us reduce code re-use. Definitely not feature complete for cfn-init, however it's one take to solve just our use case still. If this is a strategy that people like, I might have time to contribute to a PR into CDK.

@eladb eladb assigned rix0rrr and unassigned eladb Jan 23, 2020
@rix0rrr rix0rrr added @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/large Large work item – several weeks of effort labels Jan 23, 2020
@SomayaB SomayaB removed the gap label Feb 25, 2020
@ywauto83
Copy link

any update on this? @rix0rrr

@robertd
Copy link
Contributor

robertd commented May 6, 2020

Yeah, I'd really like to see this feature ship soon. Using escape hatches to accomplish this task is very cumbersome.

@Zirkonium88
Copy link

Please, keep things going on this @rix0rrr

@Zirkonium88
Copy link

With regard to another issue about adding metadata, this seems to be a work around at the moment: Modifying the AWS CloudFormation resource behind AWS constructs

@oscarnevarezleal
Copy link

I saw this is documented on the AWS CDK API under Configuring Instances using CloudFormation Init (cfn-init)
but it doesn't seem to work ( undefined init property on instanceProps ) in version @1.60.0

@ericzbeard ericzbeard added the feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs label Apr 6, 2021
@rix0rrr rix0rrr closed this as completed Aug 18, 2021
@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.

@felipeloha
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudformation Related to AWS CloudFormation @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/large Large work item – several weeks 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.