github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/docs/content/functions/aws.md (about)

     1  ---
     2  title: aws functions
     3  menu:
     4    main:
     5      parent: functions
     6  ---
     7  
     8  The functions in the `aws` namespace interface with various Amazon Web Services
     9  APIs to make it possible for a template to render differently based on the AWS
    10  environment and metadata.
    11  
    12  ### Configuring AWS
    13  
    14  A number of environment variables can be used to control how gomplate communicates
    15  with AWS APIs. A few are documented here for convenience. See [the `aws-sdk-go` documentation](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html)
    16  for details.
    17  
    18  | Environment Variable | Description |
    19  | -------------------- | ----------- |
    20  | `AWS_ANON` | Set to `true` when accessing services that do not need authentication, such as with public S3 buckets. Not part of the AWS SDK. |
    21  | `AWS_TIMEOUT` | _(Default `500`)_ Adjusts timeout for API requests, in milliseconds. Not part of the AWS SDK. |
    22  | `AWS_PROFILE` | Profile name the SDK should use when loading shared config from the configuration files. If not provided `default` will be used as the profile name. |
    23  | `AWS_REGION` | Specifies where to send requests. See [this list](https://docs.aws.amazon.com/general/latest/gr/rande.html). Note that the region must be set for AWS functions to work correctly, either through this variable, through a configuration profile, or by running on an EC2 instance. |
    24  | `AWS_EC2_METADATA_SERVICE_ENDPOINT` | _(Default `http://169.254.169.254`)_ Sets the base address of the instance metadata service. |
    25  | `AWS_META_ENDPOINT` _(Deprecated)_ | _(Default `http://169.254.169.254`)_ Sets the base address of the instance metadata service. Use `AWS_EC2_METADATA_SERVICE_ENDPOINT` instead. |
    26  
    27  ## `aws.EC2Meta`
    28  
    29  **Alias:** `ec2meta`
    30  
    31  Queries AWS [EC2 Instance Metadata](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for information. This only retrieves data in the `meta-data` path -- for data in the `dynamic` path use `aws.EC2Dynamic`.
    32  
    33  For times when running outside EC2, or when the metadata API can't be reached, a `default` value can be provided.
    34  
    35  _Added in gomplate [v1.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.8.0)_
    36  ### Usage
    37  
    38  ```
    39  aws.EC2Meta key [default]
    40  ```
    41  
    42  ### Arguments
    43  
    44  | name | description |
    45  |------|-------------|
    46  | `key` | _(required)_ the metadata key to query |
    47  | `default` | _(optional)_ the default value |
    48  
    49  ### Examples
    50  
    51  ```console
    52  $ echo '{{aws.EC2Meta "instance-id"}}' | gomplate
    53  i-12345678
    54  ```
    55  
    56  ## `aws.EC2Dynamic`
    57  
    58  **Alias:** `ec2dynamic`
    59  
    60  Queries AWS [EC2 Instance Dynamic Metadata](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for information. This only retrieves data in the `dynamic` path -- for data in the `meta-data` path use `aws.EC2Meta`.
    61  
    62  For times when running outside EC2, or when the metadata API can't be reached, a `default` value can be provided.
    63  
    64  _Added in gomplate [v1.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.8.0)_
    65  ### Usage
    66  
    67  ```
    68  aws.EC2Dynamic key [default]
    69  ```
    70  
    71  ### Arguments
    72  
    73  | name | description |
    74  |------|-------------|
    75  | `key` | _(required)_ the dynamic metadata key to query |
    76  | `default` | _(optional)_ the default value |
    77  
    78  ### Examples
    79  
    80  ```console
    81  $ echo '{{ (aws.EC2Dynamic "instance-identity/document" | json).region }}' | gomplate
    82  us-east-1
    83  ```
    84  
    85  ## `aws.EC2Region`
    86  
    87  **Alias:** `ec2region`
    88  
    89  Queries AWS to get the region. An optional default can be provided, or returns
    90  `unknown` if it can't be determined for some reason.
    91  
    92  _Added in gomplate [v1.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v1.8.0)_
    93  ### Usage
    94  
    95  ```
    96  aws.EC2Region [default]
    97  ```
    98  
    99  ### Arguments
   100  
   101  | name | description |
   102  |------|-------------|
   103  | `default` | _(optional)_ the default value |
   104  
   105  ### Examples
   106  
   107  _In EC2_
   108  ```console
   109  $ echo '{{ aws.EC2Region }}' | ./gomplate
   110  us-east-1
   111  ```
   112  _Not in EC2_
   113  ```console
   114  $ echo '{{ aws.EC2Region }}' | ./gomplate
   115  unknown
   116  $ echo '{{ aws.EC2Region "foo" }}' | ./gomplate
   117  foo
   118  ```
   119  
   120  ## `aws.EC2Tag`
   121  
   122  **Alias:** `ec2tag`
   123  
   124  Queries the AWS EC2 API to find the value of the given [user-defined tag](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html). An optional default
   125  can be provided.
   126  
   127  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   128  ### Usage
   129  
   130  ```
   131  aws.EC2Tag tag [default]
   132  ```
   133  
   134  ### Arguments
   135  
   136  | name | description |
   137  |------|-------------|
   138  | `tag` | _(required)_ the tag to query |
   139  | `default` | _(optional)_ the default value |
   140  
   141  ### Examples
   142  
   143  ```console
   144  $ echo 'This server is in the {{ aws.EC2Tag "Account" }} account.' | ./gomplate
   145  foo
   146  ```
   147  ```console
   148  $ echo 'I am a {{ aws.EC2Tag "classification" "meat popsicle" }}.' | ./gomplate
   149  I am a meat popsicle.
   150  ```
   151  
   152  ## `aws.EC2Tags`
   153  
   154  **Alias:** `ec2tags`
   155  
   156  Queries the AWS EC2 API to find all the tags/values [user-defined tag](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html).
   157  
   158  _Added in gomplate [v3.8.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.8.0)_
   159  ### Usage
   160  
   161  ```
   162  aws.EC2Tags
   163  ```
   164  
   165  ### Arguments
   166  
   167  | name | description |
   168  |------|-------------|
   169  
   170  ### Examples
   171  
   172  ```console
   173  echo '{{ range $key, $value := aws.EC2Tags }}{{(printf "%s=%s\n" $key $value)}}{{ end }}' | ./gomplate
   174  Description=foo
   175  Name=bar
   176  svc:name=foobar
   177  ```
   178  
   179  ## `aws.KMSEncrypt`_(unreleased)_
   180  **Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
   181  
   182  Encrypt an input string with the AWS Key Management Service (KMS).
   183  
   184  At most 4kb (4096 bytes) of data may be encrypted.
   185  
   186  The resulting ciphertext will be base-64 encoded.
   187  
   188  The `keyID` parameter is used to reference the Customer Master Key to use,
   189  and can be:
   190  
   191  - the key's ID (e.g. `1234abcd-12ab-34cd-56ef-1234567890ab`)
   192  - the key's ARN (e.g. `arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab`)
   193  - the alias name (aliases must be prefixed with `alias/`, e.g. `alias/ExampleAlias`)
   194  - the alias ARN (e.g. `arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias`)
   195  
   196  For information on creating keys, see [_Creating Keys_](https://docs.aws.amazon.com/kms/latest/developerguide/create-keys.html)
   197  
   198  See [the AWS documentation](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)
   199  for more details.
   200  
   201  See also [`aws.KMSDecrypt`](#aws-kmsdecrypt).
   202  
   203  ### Usage
   204  
   205  ```
   206  aws.KMSEncrypt keyID input
   207  ```
   208  ```
   209  input | aws.KMSEncrypt keyID
   210  ```
   211  
   212  ### Arguments
   213  
   214  | name | description |
   215  |------|-------------|
   216  | `keyID` | _(required)_ the ID of the Customer Master Key (CMK) to use for encryption |
   217  | `input` | _(required)_ the string to encrypt |
   218  
   219  ### Examples
   220  
   221  ```console
   222  $ export CIPHER=$(gomplate -i '{{ aws.KMSEncrypt "alias/gomplate" "hello world" }}')
   223  $ gomplate -i '{{ env.Getenv "CIPHER" | aws.KMSDecrypt }}'
   224  ```
   225  
   226  ## `aws.KMSDecrypt`
   227  
   228  Decrypt ciphertext that was encrypted with the AWS Key Management Service
   229  (KMS).
   230  
   231  The ciphertext must be base-64 encoded.
   232  
   233  See [the AWS documentation](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html)
   234  for more details.
   235  
   236  See also [`aws.KMSEncrypt`](#aws-kmsencrypt).
   237  
   238  _Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
   239  ### Usage
   240  
   241  ```
   242  aws.KMSDecrypt input
   243  ```
   244  ```
   245  input | aws.KMSDecrypt
   246  ```
   247  
   248  ### Arguments
   249  
   250  | name | description |
   251  |------|-------------|
   252  | `input` | _(required)_ the base-64 encoded ciphertext to decrypt |
   253  
   254  ### Examples
   255  
   256  ```console
   257  $ export CIPHER=$(gomplate -i '{{ aws.KMSEncrypt "alias/gomplate" "hello world" }}')
   258  $ gomplate -i '{{ env.Getenv "CIPHER" | aws.KMSDecrypt }}'
   259  ```
   260  
   261  ## `aws.Account`
   262  
   263  Returns the currently-authenticated AWS account ID number.
   264  
   265  Wraps the [STS GetCallerIdentity API](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html)
   266  
   267  See also [`aws.UserID`](#aws-userid) and [`aws.ARN`](#aws-arn).
   268  
   269  _Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
   270  ### Usage
   271  
   272  ```
   273  aws.Account
   274  ```
   275  
   276  
   277  ### Examples
   278  
   279  ```console
   280  $ gomplate -i 'My account is {{ aws.Account }}'
   281  My account is 123456789012
   282  ```
   283  
   284  ## `aws.ARN`
   285  
   286  Returns the AWS ARN (Amazon Resource Name) associated with the current authentication credentials.
   287  
   288  Wraps the [STS GetCallerIdentity API](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html)
   289  
   290  See also [`aws.UserID`](#aws-userid) and [`aws.Account`](#aws-account).
   291  
   292  _Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
   293  ### Usage
   294  
   295  ```
   296  aws.ARN
   297  ```
   298  
   299  
   300  ### Examples
   301  
   302  ```console
   303  $ gomplate -i 'Calling from {{ aws.ARN }}'
   304  Calling from arn:aws:iam::123456789012:user/Alice
   305  ```
   306  
   307  ## `aws.UserID`
   308  
   309  Returns the unique identifier of the calling entity. The exact value
   310  depends on the type of entity making the call. The values returned are those
   311  listed in the `aws:userid` column in the [Principal table](http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable)
   312  found on the Policy Variables reference page in the IAM User Guide.
   313  
   314  Wraps the [STS GetCallerIdentity API](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html)
   315  
   316  See also [`aws.ARN`](#aws-arn) and [`aws.Account`](#aws-account).
   317  
   318  _Added in gomplate [v3.4.0](https://github.com/hairyhenderson/gomplate/releases/tag/v3.4.0)_
   319  ### Usage
   320  
   321  ```
   322  aws.UserID
   323  ```
   324  
   325  
   326  ### Examples
   327  
   328  ```console
   329  $ gomplate -i 'I am {{ aws.UserID }}'
   330  I am AIDACKCEVSQ6C2EXAMPLE
   331  ```