Android app uploaded in Device Farm via AWS SDK for Go never changed status from INITIALIZED

huangapple go评论91阅读模式
英文:

Android app uploaded in Device Farm via AWS SDK for Go never changed status from INITIALIZED

问题

我正在尝试使用AWS SDK for Go来自动化在AWS设备农场中运行应用程序。但是,使用Go版本的SDK上传的任何应用程序都无法从“INITIALIZED”状态更改。如果我通过AWS控制台Web界面上传它们,那么一切都会正常。

上传代码示例:

func uploadApp(client *devicefarm.DeviceFarm, appType, projectArn string) string {
    params := &devicefarm.CreateUploadInput{
        Name:       aws.String(*appName),
        ProjectArn: aws.String(projectArn),
        Type:       aws.String(appType),
    }
    resp, err := client.CreateUpload(params)
    if err != nil {
        log.Fatal("Failed to upload an app because of: ", err.Error())
    }
    log.Println("Upload ARN:", *resp.Upload.Arn)
    return *resp.Upload.Arn
}

我得到的响应类似于:

{
  Upload: {
    Arn: "arn:aws:devicefarm:us-west-2:091463382595:upload:c632e325-266b-4bda-a74d-0acec1e2a5ae/9fbbf140-e377-4de9-b7df-dd18a21b2bca",
    Created: 2016-01-15 14:27:31 +0000 UTC,
    Name: "app-debug-unaligned.apk",
    Status: "INITIALIZED",
    Type: "ANDROID_APP",
    Url: "bla-bla-bla"
  }
}

状态从"INITIALIZED"始终不会更改。正如我所提到的,通过UI预定运行的应用程序正常工作。

如何找出原因?

=======================================
###解决方案:
1)在CreateUpload之后,需要使用响应中的预签名S3链接上传文件
2)使用收到的URL通过HTTP PUT请求执行上传,请求体中包含文件内容
3)在&devicefarm.CreateUploadInput中应指定ContentType参数。对于PUT请求,应使用相同的值作为Content-Type
4)如果从Go代码发送PUT请求,则需要手动设置Content-Length头部

英文:

I'm trying to use AWS SDK for Go to automate app runs in AWS Device Farm. But any app that uploaded with Go version of SDK never changed status from "INITIALIZED". If I upload them via AWS Console web UI, then all will be fine.

Example of code for upload:

func uploadApp(client *devicefarm.DeviceFarm, appType, projectArn string) string {
params := &devicefarm.CreateUploadInput{
Name: aws.String(*appName),
ProjectArn: aws.String(projectArn),
Type: aws.String(appType),
}
resp, err := client.CreateUpload(params)
if err != nil {
log.Fatal("Failed to upload an app because of: ", err.Error())
}
log.Println("Upload ARN:", *resp.Upload.Arn)
return *resp.Upload.Arn
}

In response I got something like:

{
Upload: {
Arn: "arn:aws:devicefarm:us-west-2:091463382595:upload:c632e325-266b-4bda-a74d-0acec1e2a5ae/9fbbf140-e377-4de9-b7df-dd18a21b2bca",
Created: 2016-01-15 14:27:31 +0000 UTC,
Name: "app-debug-unaligned.apk",
Status: "INITIALIZED",
Type: "ANDROID_APP",
Url: "bla-bla-bla"
}
}

With time status never changes from "INITIALIZED". As I mentioned, apps which run scheduled from UI works fine.

How to figure it out reason of this ?

=======================================
###Solution:

  1. After CreateUpload it requires to upload a file using pre-signed S3 link in the response
  2. Upload should be executed via HTTP PUT request by received URL with file content in the body
  3. In &devicefarm.CreateUploadInput should be specified ContentTypeparameter. For PUT request same value for Content-Type header should be used
  4. If PUT request will be send from Go code, then Content-Length header should be set manually

答案1

得分: 2

当您调用CreateUpload API时,Device Farm将返回一个包含"Url"字段的"Upload"响应。

{
  Upload: {
    Arn: "arn:aws:devicefarm:us-west-2:....",
    Created: 2016-01-15 14:27:31 +0000 UTC,
    Name: "app-name.apk",
    Status: "INITIALIZED",
    Type: "ANDROID_APP",
    Url: "bla-bla-bla"
  }
}

返回的URL,"bla-bla-bla",是一个预签名的S3 URL,用于上传您的应用程序。有关使用预签名URL上传对象的文档,请参阅:http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html

一旦您的应用程序上传完成,应用程序将被处理。您的上传状态将更改为"PROCESSING"和"SUCCEEDED"(如果出现问题,则为"FAILED")。一旦它处于"SUCCEEDED"状态,您就可以使用它来安排运行。

英文:

When you call the CreateUpload API, Device Farm will return an "Upload" response containing a "Url" field.

{
Upload: {
Arn: "arn:aws:devicefarm:us-west-2:....",
Created: 2016-01-15 14:27:31 +0000 UTC,
Name: "app-name.apk",
Status: "INITIALIZED",
Type: "ANDROID_APP",
Url: "bla-bla-bla"
}
}

The returned url, "bla-bla-bla", is a pre-signed S3 url for you to upload your application. Documentation on using a pre-signed url to upload an object: http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html

Once your application has been uploaded, the app will be processed. The status of your upload will change to "PROCESSING" and "SUCCEEDED" (or "FAILED" if something is wrong). Once it's in "SUCCEEDED" status, you can use it to schedule a run.

huangapple
  • 本文由 发表于 2016年1月15日 22:47:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/34813647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定