kubernetes/kops · error

failed to load aws config: %v

Error message

failed to load aws config: %v

What it means

getInstanceMetadataList loads AWS credentials/config via the SDK's awsconfig.LoadDefaultConfig before building an IMDS client; if no usable configuration can be resolved it wraps the error as 'failed to load aws config'. The SDK needs at least a resolvable region and credential chain.

Source

Thrown at upup/pkg/fi/nodeup/nodetasks/prefix.go:125

	return nil
}

func getInstanceMetadataFirstValue(ctx context.Context, category string) (string, error) {
	values, err := getInstanceMetadataList(ctx, category)
	if err != nil {
		return "", err
	}
	if len(values) == 0 {
		return "", fmt.Errorf("failed to get %q from ec2 meta-data: not found", category)
	}

	return values[0], nil
}

func getInstanceMetadataList(ctx context.Context, category string) ([]string, error) {
	cfg, err := awsconfig.LoadDefaultConfig(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to load aws config: %v", err)
	}
	metadata := imds.NewFromConfig(cfg)
	resp, err := metadata.GetMetadata(ctx, &imds.GetMetadataInput{Path: category})
	if err != nil {
		var awsErr *smithyhttp.ResponseError
		if errors.As(err, &awsErr) && awsErr.HTTPStatusCode() == http.StatusNotFound {
			return nil, nil
		} else {
			return nil, fmt.Errorf("failed to get %q from ec2 meta-data: %v", category, err)
		}
	}
	defer resp.Content.Close()
	lines, err := io.ReadAll(resp.Content)
	if err != nil {
		return nil, fmt.Errorf("failed to read %q from ec2 meta-data: %v", category, err)
	}

	var values []string

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Run on an EC2 instance so the SDK can resolve region/credentials from IMDS.
  2. Set AWS_REGION (or AWS_DEFAULT_REGION) and valid credentials explicitly when testing outside EC2.
  3. Check AWS_CONFIG_FILE / AWS_SHARED_CREDENTIALS_FILE paths point to readable files.

Example fix

// before (test env)
$ nodeup
// after
$ AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... nodeup
Defensive patterns

Strategy: validation

Validate before calling

if os.Getenv("AWS_REGION") == "" && !runningOnEC2() {
    return errors.New("set AWS_REGION or run on EC2")
}

Try / catch

if err != nil {
    return fmt.Errorf("AWS config unresolvable: %w; set AWS_REGION/credentials or run on EC2", err)
}

Prevention

When it happens

Trigger: LoadDefaultConfig cannot resolve a region (no AWS_REGION/AWS_DEFAULT_REGION env, no ~/.aws/config, no region from IMDS) or the credential chain fails entirely.

Common situations: nodeup binary run in an environment without the EC2 metadata fallback (e.g. on-prem, CI); misconfigured AWS_* environment variables; stripped-down images missing shared config files when AWS_SDK_LOAD_CONFIG semantics differ.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/0ee4e644800a2865. Report an issue: GitHub.