AWS Rest API无需SDK

10

由于各种原因,我不能使用AWS SDK并且需要通过REST调用API。我已经弄清楚了认证的方法,但是需要了解需要调用哪些资源。大部分AWS文档都指向他们的SDK。例如如何找到AWS密钥管理(KMS)的REST调用?

2个回答

6
请参阅此处的 AWS KMS 操作文档:
http://docs.aws.amazon.com/kms/latest/APIReference/API_Operations.html 所有服务的 AWS 端点列表:
http://docs.aws.amazon.com/general/latest/gr/rande.html
例如,us-east 中的 KMS 是 kms.us-east-1.amazonaws.com
有关 HTTPS 请求 AWS 端点的示例以及如何签署请求的说明:
http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html 因此,在签名之前,KMS ListAliases 的基本 URL 为:
https://kms.us-east-1.amazonaws.com/?Action=ListAliases&Version=2010-05-08

你从哪里得到了 2010-05-08 - falsePockets

1
这是一个使用Swift 4在iOS中通过restful命令向AWS Amazon Web Services进行PUT对象的示例。我在互联网上找不到这个内容,所以请享用。我必须自己拼凑它。我的存储桶当前设置为公共读/写。我认为要添加用户名/密码(访问密钥ID和秘密访问密钥)可以通过参数完成。这个restRequest函数有一个字典参数,可能就是可以添加的地方。但是从通过Postman进行相同写入的实验中得出,Amazon Web服务实际上希望将其作为名为“Authorization”的组合标头提供。我不确定它的确切工作原理,但是Postman具有AWS作为登录类型,因此请在那里进行实验。我从stackoverflow的某个restful示例中获得了我的restRequest restful函数。
    func restRequest(url:String, method: String, sBody: String ,
                 params: [String: String], completion: @escaping ([AnyObject])->() ){
    if let nsURL = NSURL(string:url) {
        let request = NSMutableURLRequest(url: nsURL as URL)
        if method == "PUT" {
             request.httpMethod = "PUT"
            for thisOne in params {
                request.setValue(thisOne.value, forHTTPHeaderField: thisOne.key)
            }

            request.httpBody = "some text in the file we are putting"



        }
        // Add other verbs here

        let task = URLSession.shared.dataTask(with: request as URLRequest) {
            (data, response, error) in
            do {

                // what happens if error is not nil?
                // That means something went wrong.

                // Make sure there really is some data
                if let data = data {
                    let response = try JSONSerialization.jsonObject(with: data, options:  JSONSerialization.ReadingOptions.mutableContainers)
                    completion(response as! [AnyObject])
                }
                else {
                    // Data is nil.
                }
            } catch let error as NSError {
                print("json error: \(error.localizedDescription)")
            }
        }
        task.resume()
    }
    else{
        // Could not make url. Is the url bad?
        // You could call the completion handler (callback) here with some value indicating an error
    }
}

并且像这样调用:

let urlString = "https://bucketname.s3.amazonaws.com/test.txt"

        restRequest(url: urlString, method: "PUT", sBody: sData, params: [       "Date" : "20180125T214827Z"  ]) {
            (result) in

            // Handle result here.
            print("restRequest result : \(result)")
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接