Module resty.aws.utils

AWS utility module.

Provides methods for detecting the AWS Region, as well as fetching metadata.

Functions

Utils.getCurrentRegion () Auto detects the current AWS region.
Utils.getECSTaskMetadata (subpath, version) Fetches ECS Task Metadata.
Utils.getIDMSMetadata (subpath, version) Fetches IDMS Metadata (EC2 and EKS).


Functions

Utils.getCurrentRegion ()
Auto detects the current AWS region. It will try the following options (in order);

  1. environment variable AWS_REGION
  2. environment variable AWS_DEFAULT_REGION
  3. ECS metadata V4 (parse region from "AvailabilityZone") if the environment variable ECS_CONTAINER_METADATA_URI_V4 is available
  4. ECS metadata V3 (parse region from "AvailabilityZone") if the environment variable ECS_CONTAINER_METADATA_URI is available
  5. IDMSv2 metadata (only if AWS_EC2_METADATA_DISABLED hasn't been set to true)

The IDMSv2 call makes a call to an IP endpoint, and hence could timeout (timeout is 5 seconds) if called on anything not being an EC2 or EKS instance.

Note: the result is cached so any consecutive calls will not perform any IO.

Returns:

    region, or nil+err
Utils.getECSTaskMetadata (subpath, version)
Fetches ECS Task Metadata. Both for Fargate as well as EC2 based ECS. Support version 2, 3, and 4 (version 2 is NOT available on Fargate). V3 and V4 will return an error if no url is found in the related environment variable, V2 will make a request to the IP address and hence might timeout if ran on anything else than an EC2-based ECS container.

Parameters:

  • subpath (optional) path to return data from (default "/metadata" for V2, nothing for V3+)
  • version (optional) metadata version to get "V2", "V3", or "V4" (case insensitive, default "V4")

Returns:

    body & content-type (if json, the body will be decoded to a Lua table), or nil+err
Utils.getIDMSMetadata (subpath, version)
Fetches IDMS Metadata (EC2 and EKS). Will make a call to the IP address and hence might timeout if ran on anything else than an EC2-instance. Calling this function will make the calls, it will not honor the AWS_EC2_METADATA_DISABLED setting.

Parameters:

  • subpath (optional) subpath to return data from, default /latest/meta-data/
  • version (optional) version of IDMS to use, either "V1" or "V2" (case insensitive, default "V2")

Returns:

    body & content-type (if json, the body will be decoded to a Lua table), or nil+err
generated by LDoc 1.5.0 Last updated 2024-09-23 09:29:37