0

I understand the AWS::CloudFormation::Init block of the template is executed by cfn-init script.

Here is the syntax I use to do so:

/usr/local/bin/cfn-init -v --stack  WebS<erver1 --resource WebServerInstance --region eu-central-1 --configset InstallAndRun && cat /var/log/cfn-init.log

I can do the call via UserData or via SSH.

Now I would like to have the possibility to modify the AWS::CloudFormation::Init part of the template and repeat the cnf-init call via ssh.

Question: Where is the file with the cloud formation code located on my instance, which is executed by cfn-init?

Skip
  • 6,240
  • 11
  • 67
  • 117

2 Answers2

3

The cfn-init command uses a configuration file located at /var/lib/cfn-init/data/metadata.json. The JSON file contains the config sets defined in the AWS::CloudFormation::Init block of a Cloud Formation template.

I've confirmed the path above on Amazon Linux 2. The location on other operating systems may be different.

Gunnar
  • 668
  • 5
  • 9
0

All of the cloud init files are in /var/lib/cloud (on Centos 7) and the userdata script is in /var/lib/cloud/instance

See my other answer cloud-init: What is the execution order of cloud-config directives? for general hints on where the source to cloud-init is, execution ordering

Vorsprung
  • 32,923
  • 5
  • 39
  • 63
  • Hi! Thnx for the response. Thats true, userdata is in /var/lib/cloud, but not the declarative AWS::CloudFormation::Init part. Where do I find this one, do you know? – Skip Jan 04 '18 at 15:03
  • The declarative part will be in the cloud formation template that you used to create the stack. Identify the stack that you used and then modify the template – sudheerchamarthi Jan 05 '18 at 01:28
  • A downvote here is a bit harsh (fixed, haha). The answer itself points to a good resource that should answer the question without creating duplicate content on stackoverflow. – Miles Jan 05 '18 at 06:25
  • @Miles The answer described where to find the userData scripts. Indeed the question was: where to find the declarative part, described in the AWS::CloudFormation::Init part of the template. The usecase mentioned was: modification of the template locally and retriggering of the cfn-init with a modified template, to shorten the development cycle. So the answer missed the point IMHO – Skip Jan 05 '18 at 13:46
  • @sudheerchamarthi by "modify the template" you probably mean updating the stack with a new template? Exactly this I would like to avoid in order, if I need to do a minor change and retrigger the provisioning - I would like to modify the declarative template ON THE INSTANCE and directly retrigger the cfn-init. – Skip Jan 05 '18 at 13:49