English 中文(简体)
AWSSDK 快速/临时提供全权证书
原标题:AWSSDK for Swift / supplying credentials at runtime

I am trying to list files in an S3 bucket and eventually upload and do more with the new AWSSDK.

我已成功地抽取了BELOW号样本,以便把物体(名称)列入S3桶,其代码如下: 然而,在XCode IDE环境之外操作该守则时,我的理解是,我必须提供全权证书,因为XCode消耗了当地ENVIRONMENT VARIABLES I设置的AWS钥匙。

在BUT公司经营时,我只想把客户的证书/钥匙带入手工艺品,因此不能发现ANYWHERE如何混淆AWSClient的物体,使之包括成像钥匙(ACCESS & SECRET)。

纽约市的帮助将受到极大赞赏,因为我找不到任何例子说明如何做到这一点,尽管文件表明,你可以人工地向世界妇女大会党提供这些文件。

在民主选举学会环境中开展工作的制定法规是......

import Foundation       // standard apple foundation libraries
import ClientRuntime    // low level awssdk suport features
import AWSS3            // S3 module

  func listBucketFiles(bucket: String) async throws -> [String] {
        
        // Get an S3Client with which to access Amazon S3.
        let client = try S3Client(region: "us-east-1")
        
        let input = ListObjectsV2Input(
            bucket: bucket
        )
        let output = try await client.listObjectsV2(input: input)
        var names: [String] = []
        
        guard let objList = output.contents else {
            return []
        }
        
        for obj in objList {
            if let objName = obj.key {
                names.append(objName)
            }
        }
        
        self.bucketNames = names
        
        return names
    }

see example above, the code worsks thru Xcode but in production does not authenticate

问题回答

http://docs.aws.amazon.com/sdk-for-swift/latest/developer-guide/using-configuration.html#:%7E:text=Alternatively%2C%20you%20can%20directly%20species%20the%20credentials%20inab%20of%20letting%20SDK%20obtain%20the%20m%20automatic” 等参考文献,说明的是环境因素。

let credentials = AWSCredentialsProviderStaticConfig(
    accessKey: "REPLACE_THIS",
    secret: "REPLACE_THIS"
)

let config = try await S3Client.S3ClientConfiguration(
  credentialsProvider: AWSCredentialsProvider.fromStatic(credentials),
  region: "us-east-1", 
)

let client = try S3Client(config: config)

However, if you re building a client application, please don t embed AWS credentials as they can be easily accessed by your end users. Instead, move the AWS logic to a server and communicate with it from your app using an HTTP API.





相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

BraintreeDropIn deprecated functions error

I m getting this error on the latest release of BraintreeDropIn, I really don t get it since based on the patch notes, this should ve been addressed already, I have already tried cleaning derived data,...

how to limit zoom level in map swift ui?

how to limit zoom level in map swift ui i have map and need to make zoom level limited Map(coordinateRegion: $region,annotationItems: viewModel.nearbyGyms) { item in ...

UIImageView - How to get the file name of the image assigned?

Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...

热门标签