Does metadata fetch like ECS_CONTAINER_METADATA_URI_V4 in ECS Fargate

NS 40 Reputation points
2023-10-03T10:46:44.11+00:00

We have a specific use case where we need to fetch within the running container instance using https://management.azure.com/subscriptions/<subscriber-id>/resourceGroups/<resource group id>/resourceGroups/<resource group name>/providers/Microsoft.ContainerInstance/containerGroups/<container group name> .
It appears that this API needs Subscriber ID/Container Group name/ Resource Group name which may not be available.

Is there a way to fetch this data within the container instance running some metadata API.
Some thing similar to ECS_CONTAINER_METADATA_URI_V4 like ECS Fargate

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
676 questions
{count} votes

1 answer

Sort by: Most helpful
  1. vipullag-MSFT 26,021 Reputation points
    2023-10-04T06:13:08.5566667+00:00

    Hello Neha

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Yes, you can use the Azure Instance Metadata Service (IMDS) to retrieve metadata for your container instance. IMDS is a REST API that's available at a well-known, non-routable IP address (169.254.169.254). You can only access it from within the VM. Communication between the VM and IMDS never leaves the host.

    To access IMDS, you can use the following sample code:

    curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2021-02-01"

    This will return a JSON object containing metadata about the instance, including the subscription ID, resource group name, and container group name.

    You can then parse the JSON object to extract the information you need. Here's an example of how to extract the subscription ID:

    curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2021-02-01" | jq -r .compute.subscriptionId'

    This will return the subscription ID as a string.

    I hope this information helps you.

    0 comments No comments