Skip to content

DescribeTrainingJobCommand Fails with MethodNotAllowed (POST) - Was Working Before #7022

@AbbasAlibhaiER

Description

@AbbasAlibhaiER

Checkboxes for prior research

Describe the bug

We're encountering a failure when attempting to call DescribeTrainingJobCommand from the AWS SDK for JavaScript (v3) targeting SageMaker. This was working previously, but it now fails with a MethodNotAllowed error (POST not allowed), even though the IAM policy in use grants full SageMaker access and passes the IAM Policy Simulator.

🧱 Backend code:

export class TrainingService {
  private readonly sageMakerClient: SageMakerClient;

  constructor() {
    this.sageMakerClient = new SageMakerClient({
      region: process.env.AWS_REGION,
      credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      },
    });

  async findOne(id: string) {
    const command = new DescribeTrainingJobCommand({
      TrainingJobName: 'check-1',
    });

    try {
      const response = await this.sageMakerClient.send(command);
      return response;
    } catch (err) {
      console.error('Raw response:', err?.$response?.body?.toString?.('utf8') ?? '[no body]');
      throw err;
    }
    // return response;
  }

🪵 Output:

Raw response: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MethodNotAllowed</Code><Message>The specified method is not allowed against this resource.</Message><Method>POST</Method><ResourceType>SERVICE</ResourceType><RequestId>PK8TRPAV0YCSYR4N</RequestId><HostId>6vYP4/cfZU4SuPGNrz0iwJcsoIwf36hqUBURoH+wdBcV77c9TS9cnmyes8VxKBTbrlDxZICrUAs=</HostId></Error>
[Nest] 21436  - 22/04/2025, 12:13:54   ERROR [ExceptionsHandler] SyntaxError: Unexpected token '<', "<?xml vers"... is not valid JSON
  Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.
    at JSON.parse (<anonymous>)
    at C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\node_modules\@aws-sdk\core\dist-cjs\submodules\protocols\index.js:112:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async parseJsonErrorBody (C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\node_modules\@aws-sdk\core\dist-cjs\submodules\protocols\index.js:125:17)
    at async de_CommandError (C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\dist-cjs\index.js:9897:11)   
    at async C:\Users\abbas\er_command_center_backend\node_modules\@smithy\middleware-serde\dist-cjs\index.js:35:20
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:484:18
    at async C:\Users\abbas\er_command_center_backend\node_modules\@smithy\middleware-retry\dist-cjs\index.js:320:38
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:110:22
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:137:14 {
  '$metadata': {
    attempts: 1,
    totalRetryDelay: 0
  }
}

✅ Verified

  • IAM Policy has SageMaker Full Access
  • Policy Simulator confirms the sagemaker:DescribeTrainingJob permission is Allowed
  • The training job "check-1" does exist
  • This code was working before with no changes

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.18.0

Reproduction Steps

Test the DescribeTrainingJobCommand or ListTrainingJobsCommand. Neither work

Observed Behavior

Output:

Raw response: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MethodNotAllowed</Code><Message>The specified method is not allowed against this resource.</Message><Method>POST</Method><ResourceType>SERVICE</ResourceType><RequestId>PK8TRPAV0YCSYR4N</RequestId><HostId>6vYP4/cfZU4SuPGNrz0iwJcsoIwf36hqUBURoH+wdBcV77c9TS9cnmyes8VxKBTbrlDxZICrUAs=</HostId></Error>
[Nest] 21436  - 22/04/2025, 12:13:54   ERROR [ExceptionsHandler] SyntaxError: Unexpected token '<', "<?xml vers"... is not valid JSON
  Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object.
    at JSON.parse (<anonymous>)
    at C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\node_modules\@aws-sdk\core\dist-cjs\submodules\protocols\index.js:112:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async parseJsonErrorBody (C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\node_modules\@aws-sdk\core\dist-cjs\submodules\protocols\index.js:125:17)
    at async de_CommandError (C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\client-sagemaker\dist-cjs\index.js:9897:11)   
    at async C:\Users\abbas\er_command_center_backend\node_modules\@smithy\middleware-serde\dist-cjs\index.js:35:20
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:484:18
    at async C:\Users\abbas\er_command_center_backend\node_modules\@smithy\middleware-retry\dist-cjs\index.js:320:38
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:110:22
    at async C:\Users\abbas\er_command_center_backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:137:14 {
  '$metadata': {
    attempts: 1,
    totalRetryDelay: 0
  }
}


### Expected Behavior

A JSON response of DescribeTrainingJob

### Possible Solution

_No response_

### Additional Information/Context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions