moodle/moodle · error · CredentialsException

Unexpected container metadata credentials value

Error message

Unexpected container metadata credentials value

What it means

The metadata endpoint responded, but its body did not decode to a JSON object containing an AccessKeyId. decodeResult() json_decodes the response body and throws this CredentialsException when 'AccessKeyId' is absent — meaning the response is not valid ECS container-credentials JSON.

Solutions

  1. Dump the raw response (e.g. curl the metadata URI from inside the container) to see what body is actually returned.
  2. Confirm the URI points at the real ECS credentials endpoint (http://169.254.170.2/v2/credentials/...) and the task has an IAM role attached.
  3. If using a custom FULL_URI server, make it return exactly {"AccessKeyId":..., "SecretAccessKey":..., "Token":..., "Expiration":...} JSON with HTTP 200.
  4. Check that no proxy env vars (HTTP_PROXY etc.) are intercepting the link-local request — the provider sets proxy: '' for its client but environment-level interception may still apply.
  5. Ensure the task role is attached in ECS task definition ("role" field) so the endpoint returns credentials rather than an error.

Example fix

// before: custom server returns wrong shape
{"error":"not found"}

// after: required shape
{"AccessKeyId":"ASIA...","SecretAccessKey":"...","Token":"...","Expiration":"2026-09-14T12:00:00Z"}
Defensive patterns

Strategy: try-catch

Validate before calling

<?php
$uri = getenv('AWS_CONTAINER_CREDENTIALS_RELATIVE_URI')
    ? 'http://169.254.170.2' . getenv('AWS_CONTAINER_CREDENTIALS_RELATIVE_URI')
    : getenv('AWS_CONTAINER_CREDENTIALS_FULL_URI');
if ($uri) {
    $body = @file_get_contents($uri);
    $json = json_decode((string)$body, true);
    if (!isset($json['AccessKeyId'])) {
        error_log('Metadata endpoint returned unexpected body: ' . substr((string)$body, 0, 200));
    }
}

Type guard

null

Try / catch

<?php
use Aws\Exception\CredentialsException;
try {
    $creds = $provider()->wait();
} catch (CredentialsException $e) {
    if ($e->getMessage() === 'Unexpected container metadata credentials value') {
        error_log('Metadata endpoint returned a non-credentials body; check proxy/task role/endpoint');
    }
    throw $e;
}

Prevention

When it happens

Trigger: __invoke receives an HTTP 200 response whose body is not the expected {AccessKeyId, SecretAccessKey, Token, Expiration} payload: an error/HTML page from a proxy, an empty body, a JSON error document (e.g. {"message":"..."} from a 4xx that still resolved), or a non-JSON body from a custom FULL_URI server.

Common situations: A corporate proxy or load balancer intercepting 169.254.170.2 traffic and returning an error page; custom credential servers returning a different JSON schema; the endpoint returning 404/403 JSON without AccessKeyId; truncated or gzip-encoded bodies the client did not decode.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/a0fceaaafdd8df9e. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/aws-sdk/src/Credentials/EcsCredentialProvider.php:229

        if (empty($credsUri)){
            $credFullUri = getenv(self::ENV_FULL_URI);
            if ($credFullUri === false){
                $credFullUri = $_SERVER[self::ENV_FULL_URI] ?? '';
            }

            if (!empty($credFullUri))
                return $credFullUri;
        }

        return self::SERVER_URI . $credsUri;
    }

    private function decodeResult($response)
    {
        $result = json_decode($response, true);

        if (!isset($result['AccessKeyId'])) {
            throw new CredentialsException('Unexpected container metadata credentials value');
        }
        return $result;
    }

    /**
     * Determines whether or not a given request URI is a valid
     * container credential request URI.
     *
     * @param $uri
     *
     * @return bool
     */
    private function isCompatibleUri($uri)
    {
        $parsed = parse_url($uri);

        if ($parsed['scheme'] !== 'https') {
            $host = trim($parsed['host'], '[]');

View on GitHub (pinned to 48ea8c3322)