

This is the new *CloudFormation Template Reference Guide*. Please update your bookmarks and links. For help getting started with CloudFormation, see the [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html).

# cfn-get-metadata
<a name="cfn-get-metadata"></a>

You can use the `cfn-get-metadata` helper script to fetch a metadata block from CloudFormation and print it to standard output. You can also print a sub-tree of the metadata block if you specify a key. However, only top-level keys are supported.

**Topics**
+ [Syntax](#cfn-get-metadata-Syntax)
+ [Options](#cfn-get-metadata-options)

## Syntax
<a name="cfn-get-metadata-Syntax"></a>

```
cfn-get-metadata --access-key {{access.key}} \
                 --secret-key {{secret.key}} \
                 --credential-file|f {{credential.file}} \
                 --key|k {{key}} \
                 --stack|-s {{stack.name.or.id}} \
                 --resource|-r {{logical.resource.id}} \
                 --role {{IAM.role.name}} \
                 --url|-u {{service.url}} \
                 --region {{region}}
```

**Note**  
`cfn-get-metadata` doesn't require credentials, so you don't need to use the `--access-key`, `--secret-key`, `--role`, or `--credential-file` options. However, if no credentials are specified, CloudFormation checks for stack membership and limits the scope of the call to the stack that the instance belongs to. For more information, see [Permissions for helper scripts](cfn-helper-scripts-reference.md#cfn-helper-scripts-reference-permissions).

## Options
<a name="cfn-get-metadata-options"></a>


| Name | Description | Required | 
| --- | --- | --- | 
|  `-k, --key`  | For a key-value pair, returns the name of the key for the value that you specified.<br />*Type*: String<br />*Example*: For `{ "Key1": "SampleKey1", "Key2": "SampleKey2" }`, `cfn-get-metadata -k Key2` returns `SampleKey2`. | No | 
|  `-s, --stack`  | Name of the Stack.<br />*Type*: String<br />*Default*: None<br />*Example*: `-s { "Ref" : "AWS::StackName" },` | Yes | 
|  `-r, --resource`  | The logical resource ID of the resource that contains the metadata.<br />*Type*: String<br />*Example*: `-r WebServerHost` | Yes | 
| `--role` (resource signaling only) | The name of an IAM role that's associated with the instance.<br />*Type*: String<br />Condition: The credential file parameter supersedes this parameter. | No | 
|  `--region`  | The region to derive the CloudFormation URL from.<br />*Type*: String<br />*Default*: None<br />*Example*: `--region ", { "Ref" : "AWS::Region" },` | No | 
|  `--access-key`  | AWS Access Key for an account with permission to call DescribeStackResource on CloudFormation.<br />*Type*: String<br />Condition: The credential file parameter supersedes this parameter. | Conditional | 
|  `--secret-key`  | AWS Secret Key that corresponds to the specified AWS Access Key.<br />*Type*: String<br />Condition: The credential file parameter supersedes this parameter. | Conditional | 
|  `-f, --credential-file`  | A file that contains both a secret key and an access key.<br />*Type*: String<br />Condition: The credential file parameter supersedes the --access-key and --secret-key parameters. | Conditional | 