3

我使用 AWS API Gateway 创建了一个 API,但每当我尝试访问任何资源时,都会收到此错误。

Error Domain=com.amazonaws.AWSAPIGatewayErrorDomain Code=1 "(null)" UserInfo={HTTPBody=<CFBasicHash 0x7fd5d87baaf0 [0x102c007b0]>{type = immutable dict, count = 1,
entries =>
0 : message = <CFString 0x7fd5d87bf100 [0x102c007b0]>{contents = "Not able to access resource."}
}
, HTTPHeaderFields=<CFBasicHash 0x7fd5d87bf2a0 [0x102c007b0]>{type = immutable dict, count = 8,
entries =>
0 : X-Cache = <CFString 0x7fd5d87bf030 [0x102c007b0]>{contents = "Error from cloudfront"}
1 : Content-Type = <CFString 0x7fd5d87bd900 [0x102c007b0]>{contents = "application/json"}
3 : x-amzn-RequestId = <CFString 0x7fd5d87baa70 [0x102c007b0]>{contents = "2728fe5f-51b0-11e5-8d25-ada09d3fa091"}
4 : Via = <CFString 0x7fd5d87bcfb0 [0x102c007b0]>{contents = "1.1 87b90692aeeb296771124f5335f08b68.cloudfront.net (CloudFront)"}
6 : Date = <CFString 0x7fd5d87be8d0 [0x102c007b0]>{contents = "Wed, 02 Sep 2015 20:21:11 GMT"}
10 : Content-Length = 43
11 : X-Amz-Cf-Id = <CFString 0x7fd5d87bd0f0 [0x102c007b0]>{contents = "0aL_H-QzchVHBgsYChJ9YwJOs0PKpdFzouXJsDDausqQ9bpunaJmFg=="}
12 : Connection = <CFString 0x7fd5d87be8b0 [0x102c007b0]>{contents = "keep-alive"}
}
}

我的资源需要 api 密钥但没有“授权类型”。

这是我配置客户端的 AppDelegate.swift 的片段:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
    MYREKSMyreksApiClient.registerClientWithConfiguration(configuration, forKey: "avfhh3FNkh4JDGWG8AHsH4ogucFZjmkEUJIn0C44")
    return true
}

这就是我从控制器调用的方式。

let serviceClient = CLIMyApiClient(forKey: apiKey)
    var object = CLICustomObject()
    object.param_01 = "Param 01"
    object.param_02 = "Param 02"
    let result = serviceClient.customObjectPost(contentShare).continueWithBlock{ (task:AWSTask!) -> (AnyObject!) in
        if task.error != nil {
            print(task.error)
        } else {
            print("Good!")
        }
        return nil
    }

任何想法为什么我得到那个错误?

4

1 回答 1

5

好的,我已经设法识别错误...

我的代码中有几个错误:

  1. 当我注册我的客户端“forKey”时,该键只是检索我的客户端的字典键。我并没有真正在那里添加我的 API 密钥。所以,我把它改成了一个更有意义的键。

  2. 要在客户端中实际设置我的 API 密钥,我必须......好吧,在客户端中设置它:

    let serviceClient = CLIApiClient(forKey: "MoreMeaningfulKey")
    serviceClient.APIKey = "MyActuallyAPIKey"
    

而已!

显然,在 AWS API Gateway、iOS 和 Android 团队中,他们不互相交谈。这就是你在 Android 上的称呼:

ApiClientFactory factory = new ApiClientFactory().endpoint(END_POINT).apiKey(API_KEY);
MyApiClient client = factory.build(MyApiClient.class);
于 2015-09-03T14:20:10.623 回答