aws functions

The functions in the aws namespace interface with various Amazon Web Services APIs to make it possible for a template to render differently based on the AWS environment and metadata.

Configuring AWS

A number of environment variables can be used to control how gomplate communicates with AWS APIs. A few are documented here for convenience. See the aws-sdk-go documentation for details.

Environment Variable Description
AWS_TIMEOUT (Default 500) Adjusts timeout for API requests, in milliseconds. Not part of the AWS SDK.
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.
AWS_REGION Specifies where to send requests. See this list. Note that the region must be set for AWS functions to work correctly, either through this variable, or a configuration profile.

aws.EC2Meta

Alias: (to be deprecated) ec2meta

Queries AWS EC2 Instance Metadata for information. This only retrieves data in the meta-data path – for data in the dynamic path use aws.EC2Dynamic.

This only works when running gomplate on an EC2 instance. If the EC2 instance metadata API isn’t available, the tool will timeout and fail.

Example

$ echo '{{aws.EC2Meta "instance-id"}}' | gomplate
i-12345678

aws.EC2Dynamic

Alias: (to be deprecated) ec2dynamic

Queries AWS EC2 Instance Dynamic Metadata for information. This only retrieves data in the dynamic path – for data in the meta-data path use aws.EC2Meta.

This only works when running gomplate on an EC2 instance. If the EC2 instance metadata API isn’t available, the tool will timeout and fail.

Example

$ echo '{{ (aws.EC2Dynamic "instance-identity/document" | json).region }}' | ./gomplate
us-east-1

aws.EC2Region

Alias: (to be deprecated) ec2region

Queries AWS to get the region. An optional default can be provided, or returns unknown if it can’t be determined for some reason.

Example

In EC2

$ echo '{{ aws.EC2Region }}' | ./gomplate
us-east-1

Not in EC2

$ echo '{{ aws.EC2Region }}' | ./gomplate
unknown
$ echo '{{ aws.EC2Region "foo" }}' | ./gomplate
foo

aws.EC2Tag

Alias: (to be deprecated) ec2tag

Queries the AWS EC2 API to find the value of the given user-defined tag. An optional default can be provided.

Example

$ echo 'This server is in the {{ aws.EC2Tag "Account" }} account.' | ./gomplate
foo
$ echo 'I am a {{ aws.EC2Tag "classification" "meat popsicle" }}.' | ./gomplate
I am a meat popsicle.