How to use AWS Device Farm API

Hi All,
If you are here it's means you trying to do something I tried longer than you guys tried. If you are in a hurry go to "Implementation" subheading and read from there.

Background & Reason

While I was doing my internship, one of the project I had to do is make a web app for get the test result customize way from AWS Device farm using AWD Device Farm API.
My first approach was use postman to get a main idea about the API but I failed on that. I raise a question how to use their API in AWS but I didn't get a good answer either. ( For your reference if it update in future :- Using REST in Postman )

So at the end I decide to use their AWS SDK for JavaScript in Node and create a wrapper around it to get the data. The main reason to write this post was most of guys will confuse how to get the result because AWS ARN thing is really confusing at first.

Implementation. 

Requirements.

Since I'm going to use AWS SDK version of Node. You'll need NodeJS.
Additionally I'll use ExpressJS to server side.

Set up.

Set up expressJS. If you don't know how to do that go through this Link.
And then install AWS-SDK.
npm install aws-sdk
After that create a config.json file in the root directory and put these configs.

  {
    "accessKeyId": "",
    "secretAccessKey": "",
    "region": "us-west-2",
    "apiVersion" : "2015-06-23"
  }

And then create a route and add these to top of that file.

var AWS = require('aws-sdk');

AWS.config.loadFromPath('./config.json');
var devicefarm = new AWS.DeviceFarm();


A For example I’ll list all the project and return it as a JSON.

devicefarm.listProjects({}, function(err, data) {        
        if (err) console.log(err, err.stack); // an error occurred
        else {
            console.log(data);
            res.send(data);
        } 
    });

To get a main idea about the API and Javascript API go through these two links.


About AWS Device Farm ARN

This is the most confusing part. Specially when we have to pass arn as a argument in AWS API it doesn't say which arn we should pass. So i created a table for method what arn we can pass. (This table is not complete yet. Will update soon)


Api Method
Name
ARN
project run job suites test
listRuns OK
listJobs OK
listSuites OK
listTests OK
listArtifacts
OK OK OK
1. API Calls and ARN


To understand device farm arn

Device Farm ARN
2. Test ARN


As the starting point we can run
apicalls/projects 
In AWS api "listProjects" and get all the project per that account with the project ARN.
Then we can copy arn of the project we want. Then we will pass that to
apicalls/runs?arn=arn:aws:devicefarm:us-west-2:<account_id>:project:&project=<project_id>
For Ex : apicalls/runs?arn=arn:aws:devicefarm:us-west-2:705582597265:project:&project=2c21a412-bb7b-4657-a28c-d7d78b3888f7

In AWS api "listRuns" with a param.arn = arn:aws:devicefarm:us-west-2:<account_id>:project:<project_id>. This will return all the run per that project.

Like wise you can use Device Farm API to get anything from their results. I hope you guys understand how Device Farm ARN works.

Still if you don't understand this grab the code from GitHub :  AWS Device Farm Node Wrapper.
And explore. :) 




Comments

Popular posts from this blog

Student Enrollment System - Requirement & Design Stage

Cordova File Transfer plugin error 3