Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SageMakerRuntimeClient->invokeEndpointAsync() requires 'Body' parameter #2761

Closed
volosan opened this issue Aug 16, 2023 · 3 comments
Closed
Assignees
Labels
bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@volosan
Copy link

volosan commented Aug 16, 2023

Describe the bug

I`m trying to use invokeEndpointAsync() method of SageMakerRuntimeClient. When i try to run my code, I've got InvalidArgumentException:

Found 1 error while validating the input provided for the InvokeEndpoint operation:
[Body] is missing and is a required parameter

Please pay your attention: according to documentation 'Body' is not required for invokeEndpointAsync() method.

My code:

public function handle()
{
    $client = new \Aws\SageMakerRuntime\SageMakerRuntimeClient([
        'aws_access_key_id' => 'SOMEACCESSKEYID0002',
        'aws_secret_access_key' => 'soMeSECre111A66e77Key',
        'region' => 'us-east-1',
    ]);

    $result = $client->invokeEndpointAsync([
        'EndpointName' => 'some-model-async-staging',
        'InputLocation' => 'https://some-aws-bucket.s3.eu-central-1.amazonaws.com/64d38638e531964edd0ee6ca/conversions/file.011.jpg',
    ]);

    print_r($result);
}

So, if I'll add 'Body' => '' to method parameters, I'll receive GuzzleHttp\Promise\Promise instead of result that's I've expected according to documentation:

GuzzleHttp\Promise\Promise {#507
  -state: "pending"
  -result: null
  -cancelFn: array:2 [
    0 => GuzzleHttp\Promise\Promise {#524
      -state: "pending"
      -result: null
      -cancelFn: array:2 [
        0 => GuzzleHttp\Promise\Promise {#523
          -state: "pending"
          -result: null
          -cancelFn: array:2 [
            0 => GuzzleHttp\Promise\Promise {#521
              -state: "pending"
              -result: null
              -cancelFn: array:2 [
                0 => GuzzleHttp\Promise\Promise {#519
                  -state: "pending"
                  -result: null
                  -cancelFn: array:2 [
                    0 => GuzzleHttp\Promise\Promise {#517
                      -state: "pending"
                      -result: null
                      -cancelFn: array:2 [
                        0 => GuzzleHttp\Promise\Promise {#516
                          -state: "pending"
                          -result: null
                          -cancelFn: array:2 [
                            0 => GuzzleHttp\Promise\Promise {#513
                              -state: "pending"
                              -result: null
                              -cancelFn: array:2 [
                                0 => GuzzleHttp\Promise\Promise {#511
                                  -state: "pending"
                                  -result: null
                                  -cancelFn: array:2 [
                                    0 => GuzzleHttp\Promise\Promise {#510
                                      -state: "pending"
                                      -result: null
                                      -cancelFn: array:2 [
                                        0 => GuzzleHttp\Promise\Promise {#509 …6}
                                        1 => "cancel"
                                      ]
                                      -waitFn: null
                                      -waitList: array:2 [
                                        0 => GuzzleHttp\Promise\Promise {#514 …6}
                                        1 => GuzzleHttp\Promise\Promise {#509}
                                      ]
                                      -handlers: array:1 [
                                        0 => array:3 [ …3]
                                      ]
                                    }
                                    1 => "cancel"
                                  ]
                                  -waitFn: null
                                  -waitList: array:3 [
                                    0 => GuzzleHttp\Promise\Promise {#514}
                                    1 => GuzzleHttp\Promise\Promise {#509}
                                    2 => GuzzleHttp\Promise\Promise {#510}
                                  ]
                                  -handlers: array:1 [
                                    0 => array:3 [
                                      0 => GuzzleHttp\Promise\Promise {#513}
                                      1 => null
                                      2 => Closure() {#390
                                        class: "Aws\Credentials\CredentialProvider"
                                        use: { …2}
                                      }
                                    ]
                                  ]
                                }
                                1 => "cancel"
                              ]
                              -waitFn: null
                              -waitList: array:4 [
                                0 => GuzzleHttp\Promise\Promise {#514}
                                1 => GuzzleHttp\Promise\Promise {#509}
                                2 => GuzzleHttp\Promise\Promise {#510}
                                3 => GuzzleHttp\Promise\Promise {#511}
                              ]
                              -handlers: array:1 [
                                0 => array:3 [
                                  0 => GuzzleHttp\Promise\Promise {#516}
                                  1 => null
                                  2 => Closure() {#398
                                    class: "Aws\Credentials\CredentialProvider"
                                    use: {
                                      $profile: "profile default"
                                      $filename: "/home/vagrant/.aws/config"
                                      $config: []
                                    }
                                  }
                                ]
                              ]
                            }
                            1 => "cancel"
                          ]
                          -waitFn: null
                          -waitList: array:5 [
                            0 => GuzzleHttp\Promise\Promise {#514}
                            1 => GuzzleHttp\Promise\Promise {#509}
                            2 => GuzzleHttp\Promise\Promise {#510}
                            3 => GuzzleHttp\Promise\Promise {#511}
                            4 => GuzzleHttp\Promise\Promise {#513}
                          ]
                          -handlers: array:1 [
                            0 => array:3 [
                              0 => GuzzleHttp\Promise\Promise {#517}
                              1 => null
                              2 => Aws\Credentials\InstanceProfileProvider {#399
                                -profile: null
                                -client: Aws\Handler\GuzzleV6\GuzzleHandler {#400
                                  -client: GuzzleHttp\Client {#401
                                    -config: array:8 [
                                      "handler" => GuzzleHttp\HandlerStack {#402
                                        -handler: Closure(RequestInterface $request, array $options): PromiseInterface {#409 …3}
                                        -stack: array:4 [ …4]
                                        -cached: null
                                      }
                                      "allow_redirects" => array:5 [
                                        "max" => 5
                                        "protocols" => array:2 [ …2]
                                        "strict" => false
                                        "referer" => false
                                        "track_redirects" => false
                                      ]
                                      "http_errors" => true
                                      "decode_content" => true
                                      "verify" => true
                                      "cookies" => false
                                      "idn_conversion" => false
                                      "headers" => array:1 [
                                        "User-Agent" => "GuzzleHttp/7"
                                      ]
                                    ]
                                  }
                                }
                                -retries: 3
                                -attempts: null
                                -timeout: 1.0
                                -secureMode: true
                              }
                            ]
                          ]
                        }
                        1 => "cancel"
                      ]
                      -waitFn: null
                      -waitList: array:6 [
                        0 => GuzzleHttp\Promise\Promise {#514}
                        1 => GuzzleHttp\Promise\Promise {#509}
                        2 => GuzzleHttp\Promise\Promise {#510}
                        3 => GuzzleHttp\Promise\Promise {#511}
                        4 => GuzzleHttp\Promise\Promise {#513}
                        5 => GuzzleHttp\Promise\Promise {#516}
                      ]
                      -handlers: array:1 [
                        0 => array:3 [
                          0 => GuzzleHttp\Promise\Promise {#519}
                          1 => Closure(CredentialsInterface $creds) {#518
                            class: "Aws\Credentials\CredentialProvider"
                            use: {
                              $provider: Closure($previousCreds = null) {#414 …}
                              $isConstant: & null
                              $result: GuzzleHttp\Promise\Promise {#517}
                            }
                          }
                          2 => null
                        ]
                      ]
                    }
                    1 => "cancel"
                  ]
                  -waitFn: null
                  -waitList: array:7 [
                    0 => GuzzleHttp\Promise\Promise {#514}
                    1 => GuzzleHttp\Promise\Promise {#509}
                    2 => GuzzleHttp\Promise\Promise {#510}
                    3 => GuzzleHttp\Promise\Promise {#511}
                    4 => GuzzleHttp\Promise\Promise {#513}
                    5 => GuzzleHttp\Promise\Promise {#516}
                    6 => GuzzleHttp\Promise\Promise {#517}
                  ]
                  -handlers: array:1 [
                    0 => array:3 [
                      0 => GuzzleHttp\Promise\Promise {#521}
                      1 => null
                      2 => Closure($reason) {#520
                        class: "Aws\Credentials\CredentialProvider"
                        use: {
                          $result: GuzzleHttp\Promise\Promise {#517}
                        }
                      }
                    ]
                  ]
                }
                1 => "cancel"
              ]
              -waitFn: null
              -waitList: array:8 [
                0 => GuzzleHttp\Promise\Promise {#514}
                1 => GuzzleHttp\Promise\Promise {#509}
                2 => GuzzleHttp\Promise\Promise {#510}
                3 => GuzzleHttp\Promise\Promise {#511}
                4 => GuzzleHttp\Promise\Promise {#513}
                5 => GuzzleHttp\Promise\Promise {#516}
                6 => GuzzleHttp\Promise\Promise {#517}
                7 => GuzzleHttp\Promise\Promise {#519}
              ]
              -handlers: array:1 [
                0 => array:3 [
                  0 => GuzzleHttp\Promise\Promise {#523}
                  1 => Closure(CredentialsInterface $creds) {#522
                    class: "Aws\Middleware"
                    use: {
                      $handler: Aws\ClientSideMonitoring\ApiCallAttemptMonitoringMiddleware {#471 …}
                      $command: Aws\Command {#312 …}
                      $signer: Aws\Signature\SignatureV4 {#515 …}
                      $request: GuzzleHttp\Psr7\Request {#508 …}
                    }
                  }
                  2 => null
                ]
              ]
            }
            1 => "cancel"
          ]
          -waitFn: null
          -waitList: array:9 [
            0 => GuzzleHttp\Promise\Promise {#514}
            1 => GuzzleHttp\Promise\Promise {#509}
            2 => GuzzleHttp\Promise\Promise {#510}
            3 => GuzzleHttp\Promise\Promise {#511}
            4 => GuzzleHttp\Promise\Promise {#513}
            5 => GuzzleHttp\Promise\Promise {#516}
            6 => GuzzleHttp\Promise\Promise {#517}
            7 => GuzzleHttp\Promise\Promise {#519}
            8 => GuzzleHttp\Promise\Promise {#521}
          ]
          -handlers: array:1 [
            0 => array:3 [
              0 => GuzzleHttp\Promise\Promise {#524}
              1 => Closure($value) {#503
                class: "Aws\RetryMiddleware"
                this: Aws\RetryMiddleware {#473 …}
                use: {
                  $handler: Closure(CommandInterface $command, RequestInterface $request) {#472 …}
                  $decider: Closure($retries, CommandInterface $command, RequestInterface $request, ResultInterface $result = null, $error = null) {#434 …}
                  $delay: array:2 [
                    0 => "Aws\RetryMiddleware"
                    1 => "exponentialDelay"
                  ]
                  $command: Aws\Command {#312 …}
                  $request: GuzzleHttp\Psr7\Request {#508 …}
                  $retries: 0
                  $requestStats: []
                  $monitoringEvents: []
                  $g: Closure($value) {#503}
                }
              }
              2 => Closure($value) {#503}
            ]
          ]
        }
        1 => "cancel"
      ]
      -waitFn: null
      -waitList: array:10 [
        0 => GuzzleHttp\Promise\Promise {#514}
        1 => GuzzleHttp\Promise\Promise {#509}
        2 => GuzzleHttp\Promise\Promise {#510}
        3 => GuzzleHttp\Promise\Promise {#511}
        4 => GuzzleHttp\Promise\Promise {#513}
        5 => GuzzleHttp\Promise\Promise {#516}
        6 => GuzzleHttp\Promise\Promise {#517}
        7 => GuzzleHttp\Promise\Promise {#519}
        8 => GuzzleHttp\Promise\Promise {#521}
        9 => GuzzleHttp\Promise\Promise {#523}
      ]
      -handlers: array:1 [
        0 => array:3 [
          0 => GuzzleHttp\Promise\Promise {#507}
          1 => Closure($value) {#506
            class: "Aws\ClientSideMonitoring\ApiCallMonitoringMiddleware"
            this: Aws\ClientSideMonitoring\ApiCallMonitoringMiddleware {#481 …}
            use: {
              $eventData: null
              $enabled: false
            }
          }
          2 => Closure($value) {#506}
        ]
      ]
    }
    1 => "cancel"
  ]
  -waitFn: null
  -waitList: array:11 [
    0 => GuzzleHttp\Promise\Promise {#514}
    1 => GuzzleHttp\Promise\Promise {#509}
    2 => GuzzleHttp\Promise\Promise {#510}
    3 => GuzzleHttp\Promise\Promise {#511}
    4 => GuzzleHttp\Promise\Promise {#513}
    5 => GuzzleHttp\Promise\Promise {#516}
    6 => GuzzleHttp\Promise\Promise {#517}
    7 => GuzzleHttp\Promise\Promise {#519}
    8 => GuzzleHttp\Promise\Promise {#521}
    9 => GuzzleHttp\Promise\Promise {#523}
    10 => GuzzleHttp\Promise\Promise {#524}
  ]
  -handlers: []
}

Expected Behavior

Expected result according to documentation:

[
    'FailureLocation' => '<string>',
    'InferenceId' => '<string>',
    'OutputLocation' => '<string>',
]

Result from working example for the same method (on Python):

{
    "ResponseMetadata": {
        "RequestId": "623a6c0e-1970-495e-a654-b8e98d64c6e8",
        "HTTPStatusCode": 202,
        "HTTPHeaders": {
            "x-amzn-requestid": "623a6c0e-1970-495e-a654-b8e98d64c6e8",
            "x-amzn-sagemaker-outputlocation": "s3://async-output/24deaa9a-4baf-8ec2-3068f968fea9.out",
            "date": "Wed, 16 Aug 2023 12:36:31 GMT",
            "content-type": "application/json",
            "content-length": "54",
            "connection": "keep-alive"
        },
        "RetryAttempts": 0
    },
    "OutputLocation": "s3://async-output/24deaa9a-4baf-8ec2-3068f968fea9.out",
    "InferenceId": "144b388d-f456-400d-9e15-83b576cc57e0"
}

Python code:

import json
import boto3
from botocore.config import Config


client = boto3.client(
        service_name = "sagemaker-runtime",
        region_name = "us-east-1",
        aws_access_key_id = 'SOMEACCESSKEYID0002',
        aws_secret_access_key = 'soMeSECre111A66e77Key'
    )

response = client.invoke_endpoint_async(
    EndpointName='some-model-async-staging',
    InputLocation='https://some-aws-bucket.s3.eu-central-1.amazonaws.com/64d38638e531964edd0ee6ca/conversions/file.011.jpg'
)

pretty = json.dumps(response, indent=4)

print(pretty)

Current Behavior

   InvalidArgumentException 

  Found 1 error while validating the input provided for the InvokeEndpoint operation:
[Body] is missing and is a required parameter

  at vendor/aws/aws-sdk-php/src/Api/Validator.php:65
     61▕                 implode("\n", $this->errors)
     62▕             );
     63▕             $this->errors = [];
     64▕ 
  ➜  65▕             throw new \InvalidArgumentException($message);
     66▕         }
     67▕     }
     68▕ 
     69▕     private function dispatch(Shape $shape, $value)

      +4 vendor frames 

  5   app/Commands/AwsCommand.php:39
      Aws\AwsClient::__call()
      +13 vendor frames 

  19  application:35
      LaravelZero\Framework\Kernel::handle()

Reproduction Steps

public function handle()
{
    $client = new \Aws\SageMakerRuntime\SageMakerRuntimeClient([
        'aws_access_key_id' => 'SOMEACCESSKEYID0002',
        'aws_secret_access_key' => 'soMeSECre111A66e77Key',
        'region' => 'us-east-1',
    ]);

    $result = $client->invokeEndpointAsync([
        'EndpointName' => 'some-model-async-staging',
        'InputLocation' => 'https://some-aws-bucket.s3.eu-central-1.amazonaws.com/64d38638e531964edd0ee6ca/conversions/file.011.jpg',
    ]);

    print_r($result);
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

3.278

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP version: 8.2.1, OS: Ubuntu 20.04.5 LTS

@volosan volosan added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 16, 2023
@yenfryherrerafeliz
Copy link
Contributor

yenfryherrerafeliz commented Aug 17, 2023

Hi @v-s-public, thanks for reporting this. I can confirm that this is an issue, and is due to that per each client's operation we define an async method, so that if the client has an operation called "listUsers", we create two methods for that client, listUsers and listUsersAsync, but in this case, sagemakerruntime client has an operation called InvokeEndpoint, and hence we create an async method for that operation called InvokeEndpointAsync, but sagemakerruntime also has an operation called InvokeEndpointAsync which conflicts with the async method for InvokeEndpoint. A possible workaround would be for you to the following:

<?php
require '../vendor/autoload.php';

use  \Aws\SageMakerRuntime\SageMakerRuntimeClient;

$client = new SageMakerRuntimeClient([
    'region' => 'us-east-2',
    'version' => 'latest'
]);
$result = $client->invokeEndpointAsyncAsync([
    'EndpointName' => 'some-model-async-staging',
    'InputLocation' => 'https://some-aws-bucket.s3.eu-central-1.amazonaws.com/64d38638e531964edd0ee6ca/conversions/file.011.jpg',
])->wait();

Please let me know if that helps!

Thanks!

@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Aug 17, 2023
@yenfryherrerafeliz yenfryherrerafeliz added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 17, 2023
@volosan
Copy link
Author

volosan commented Aug 17, 2023

Thank you @yenfryherrerafeliz! Now I have expected results.

@volosan volosan closed this as completed Aug 17, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants