swift - 如何使用 AWS Mobile Hub Helper 调用 lambda 函数?

标签 swift amazon-web-services aws-lambda aws-mobilehub amazon-mobile-hub

我目前无法使用 AWS Mobile Helper 在 Swift 中调用 lambda。

我已成功配置我的项目以使用 Cognito 用户池和 Cognito 联合身份识别用户。

但是现在调用 lambda 函数会导致崩溃: 以 NSException 类型的未捕获异常终止

崩溃前有如下日志:

AWSiOSSDK v2.4.11 [Debug] AWSInfo.m line:122 | -[AWSServiceInfo     initWithInfoDictionary:checkRegion:] | Couldn't read the region configuration from Info.plist for the client. Please check your `Info.plist` if you are providing the SDK configuration values through `Info.plist`.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.'

代码如下:

let lambda = AWSLambda.defaultLambda()

lambda.invoke(myRequest, completionHandler: {
            (myAnswer: AWSLambdaInvocationResponse?, error: NSError?) in

   print("ERROR HERE: \(error)")
   let payload = myAnswer?.payload
   print("PAYLOAD HERE: \(payload)")

})

最佳答案

如果您使用的是 Mobile Hub 或 Mobile Hub Helper,则应使用它提供的类。当您实例化 CloudLogic 单例时,它会设置服务配置。

因此,您应该使用 AWSCloudLogic.defaultCloudLogic 而不是 AWSLambda.defaultLambda,它的方法将在实例化后立即管理权限问题。

您可以通过使用移动中心下载使用云逻辑的示例应用程序来获取示例。

我整理了一个移动集线器的简图

mobile hub diagram

关于swift - 如何使用 AWS Mobile Hub Helper 调用 lambda 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40631163/

相关文章:

ios - Swift中的关联对象,全局键是否实际产生特定实例?

swift - 如何设置标签栏徽章?

amazon-web-services - Lambda 函数中的 DynamoDB BatchGetItem 动态表名

amazon-web-services - 使用 AWS CDK 创建 VPC 时如何排除路由表及其路由的默认创建

amazon-web-services - Amazon Lambda 写入 DynamoDB

java - AWS Lambda 和 S3 - 上传的 pdf 文件为空白

ios - 在 Swift 的某个时间停止 AVAudioPlayer

swift - XCode 8 Beta 6 中引入的 UISlider 错误的解决方法?

mysql - 在 AWS RDS 上混合使用 MyISAM 和 InnoDB 的问题

amazon-web-services - API 网关和 Lambda 的地理限制