AWS CloudFormation
User Guide (API Version 2010-05-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

cfn-hup

Description

The cfn-hup helper is a daemon that detects changes in resource metadata and runs user-specified actions when a change is detected. This allows you to make configuration updates on your running Amazon EC2 instances through the UpdateStack API action.

Syntax

cfn-hup --config|-c config.dir \
        --no-daemon \
        --verbose|-v

Options

NameDescriptionRequired

--no-daemon

If true, run cfn-hup once and exit.

Type: Boolean

Default: false

Yes

-v, --verbose

If true, use verbose mode.

Type: Boolean

Default: false

No

cfn-hup.conf Configuration File

The cfn-hup.conf file stores the name of the stack and the AWS credentials that the cfn-hup daemon targets. The cfn-hup.conf file uses the following format:

[main]
stack=<stack-name-or-id>  
NameDescriptionRequired

stack

A stack name or ID.

Type: String.

Yes

credential-file

An owner-only credential file, in the same format used for the command line tools.

Example:

Note

cfn-hup does not require credentials, so you do not need to use the --credential-file option.

Yes

region

The name of the AWS region containing the stack.

Example: us-east-1

No

interval

interval used to check for changes to the resource metadata in minutes

Type: Number

Default: 10

No

hooks.conf Configuration File

The user actions that the cfn-hup daemon calls periodically are defined in the hooks.conf configuration file. The hooks.conf file uses the following format:

[hookname]
triggers=post.add|post.update|post.remove
path=Resources.<logicalResourceId> (.Metadata|PhysicalResourceId)(.optionalMetadatapath)
action=<arbitrary shell command> 
runas=<runas user>  

When the action is run, it is run in a copy of the current environment (that cfn-hup is in), with CFN_OLD_METADATA set to the previous value of path, and CFN_NEW_METADATA set to the current value.

The hooks configuration file is loaded at cfn-hup daemon startup only, so new hooks will require the daemon to be restarted. A cache of previous metadata values is stored at /var/lib/cfn-hup/data/metadata_db (not human readable)—you can delete this cache to force cfn-hup to run all post.add actions again.

NameDescriptionRequired

hookname

A unique name for this hook

Type: String.

Yes

triggers

A comma-delimited list of conditions to detect.

Valid values: post.add | post.update | post.remove

Example: post.add, post.update

Yes

path

The path to the metadata object. Supports an arbitrarily deep path within the Metadata block.

Path format options

  • Resources.<LogicalResourceId>—monitor the last updated time of the resource, triggering on any change to the resource.

  • Resources.<LogicalResourceId>.PhysicalResourceId—monitor the physical ID of the resource, triggering only when the associated resource identity changes (such as a new EC2 instance).

  • Resources.<LogicalResourceId>.Metadata(.optional path)—monitor the metadata of a resource for changes (a metadata subpath may be specified to an arbitrarily deep level to monitor specific values).

Yes

action

An arbitrary shell command that is run as given.

Yes

runas

A user to run the commands as. Cfn-hup uses the su command to switch to the user.

Yes

hooks.d Directory

To support composition of several applications deploying change notification hooks, cfn-hup supports a directory named hooks.d that is located in the hooks configuration directory. You can place one or more additional hooks configuration files in the hooks.d directory. The additional hooks files must use the same layout as the hooks.conf file.

The cfn-hup daemon parses and loads each file in this directory. If any hooks in the hooks.d directory have the same name as a hook in hooks.conf, the hooks will be merged (meaning hooks.d will overwrite hooks.conf for any values that both files specify).