aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.08k stars 575 forks source link

Can't get private devices in Node #4732

Closed nickohold closed 1 year ago

nickohold commented 1 year ago

Checkboxes for prior research

Describe the bug

I have a project with private devices, which I've been using to manually schedule runs via the AWS platform, successfully. I also have a script to schedule runs programmatically, which works great for public devices. However, whenever I use a filter in ListDevicesCommand, like this:

[{"attribute": "FLEET_TYPE", "operator": "EQUALS", "values": ["PRIVATE"]}]

or in ScheduleRunCommand after using a hardcoded ARN of one of my private devices, as such:

deviceSelectionConfiguration: {
  filters: [
    {
      attribute: "ARN",
      operator: "EQUALS",
      values: [arn],
    },
  ],
  maxDevices: 1,
},

I get 0 devices back.

Running the same command from the cli:

aws devicefarm list-devices --filters '[{"attribute": "FLEET_TYPE", "operator": "EQUALS", "values": ["PRIVATE"]}]' --region us-west-2

works as expected, and I get the private devices in the response.

The credentials used are the same (same credentials file), so it's not a permissions issue. The setup has been verified by an AWS device farm expert.

I am at a loss, and can't figure out what is wrong. I have followed the documentation to the tee.

SDK version number

@aws-sdk/client-device-farm@3.267.0 & 3.332.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v16.14.2

Reproduction Steps

public async getDevices() {
    const options = {
        filters: [{ "attribute": "FLEET_TYPE", "operator": "EQUALS", "values": ["PRIVATE"] }],
    };
    const command = new ListDevicesCommand(options);
    const data = await this.deviceFarm.send(command);
    debug(`Got devices ${JSON.stringify(data)}`);
    if (!data || !data.devices) {
        throw new Error("No devices found");
    }
}

Observed Behavior

{
  "$metadata": {
    "httpStatusCode": 200,
    "requestId": "5bcd6d2d-d27a-46a3-89b4-aab09430bb3e",
    "attempts": 1,
    "totalRetryDelay": 0
  },
  "devices": [],
  "nextToken": "eyJpZCI6eyJzIjoiRjM1OEFFQjFEMkRBNDFCRkFDOTEyQ0ZDNEQwRkVCREEvMTAwMDA5MyIsIm4iOm51bGwsImIiOm51bGwsIm0iOm51bGwsImwiOm51bGwsImJvb2wiOm51bGwsInNzIjpudWxsLCJucyI6bnVsbCwiYnMiOm51bGwsIm51bGwiOm51bGx9fQ=="
}

Expected Behavior

Same functionality as the CLI: To get a list of the private devices we have under our project (4).

Possible Solution

No response

Additional Information/Context

No response

Yurish-IL commented 1 year ago

+1 same here

shavit-trop commented 1 year ago

+1

Avital-r commented 1 year ago

same

yenfryherrerafeliz commented 1 year ago

Hi @nickohold, thanks for reporting this. Could any of you (@nickohold, @Yurish-IL, @shavit-trop, @Avital-r) please run the code below and post the results here?. It is just to understand if the issue is with the deserialization of the response, or with the response that comes from the service itself.

import {DeviceFarmClient, ListDevicesCommand} from "@aws-sdk/client-device-farm";
import {NodeHttpHandler} from "@aws-sdk/node-http-handler";

class CustomHandler extends NodeHttpHandler {
    async handle(request, {abortSignal}) {
        const response = await super.handle(request, {abortSignal});
        const body = response.response.body;
        let data = "";
        body.on('data', (chunk) => {
            data += Buffer.from(chunk).toString()
        });
        body.on('end', () => {
            console.log('Data: ', data);
        });

        return response;
    }
}
const client = new DeviceFarmClient({
    region: 'us-west-2',
    requestHandler: new CustomHandler()
});
client.middlewareStack.add(next => args => {
    console.log('Request: ', args.request);

    return next(args);
}, {
    step: "finalizeRequest"
});
client.send(new ListDevicesCommand({
    filters: [
        {
            attribute: "FLEET_TYPE",
            operator: "EQUALS",
            values: [
                "PRIVATE"
            ]
        }
    ]
})).catch(console.log);

Note: Please make sure you redact any sensitive information, such as credentials.

Thanks!

RanVaknin commented 1 year ago

Just a reminder for the folks on the thread. We monitor engagement based on reactions, you can use the 👍 reaction button instead of commenting +1.

Thanks, Ran~

nickohold commented 1 year ago

Hi @RanVaknin. Here's the response of ListDevicesCommand:

Data: {"devices":[],"nextToken":"eyJpZCI6eyJzIjoiQkNDMEZDNzkzNEIyNDM1OEE1QjM1QzFGOTk5NjIyNUMvMTAwMDM4OSIsIm4iOm51bGwsImIiOm51bGwsIm0iOm51bGwsImwiOm51bGwsImJvb2wiOm51bGwsIm5zIjpudWxsLCJzcyI6bnVsbCwiYnMiOm51bGwsIm51bGwiOm51bGx9fQ=="}

nickohold commented 1 year ago

@RanVaknin did you see my last response? I was wondering if you have any follow-up, we're really stuck on this, it's a crucial part of an automation run on the device farm, and basically nullifies the usage of the device farm.

Thank you!

Yurish-IL commented 1 year ago

@yenfryherrerafeliz Please see @nickohold 's reply

aristeia commented 1 year ago

Hey folks, it turns out this is more of a pagination issue with the API than an SDK issue. The API is returning a valid response, as well as a next token, with the expectation for the user to use that next token regardless of the fact that zero devices were found on the first page. It appears that, when filtering devices, the desired filtered device can often be on the second or third page, and that the filter filters out all devices on the first page.

I am syncing with the Device Farm service team to determine next steps given this behavior.

yenfryherrerafeliz commented 1 year ago

@aristeia thanks for letting us know. I will close this as completed.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.