【问题标题】:How to invoke lambda function using AWS Mobile Hub Helper?如何使用 AWS Mobile Hub Helper 调用 lambda 函数?
【发布时间】:2016-11-16 11:37:26
【问题描述】:

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

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

但是现在调用 lambda 函数会导致崩溃: terminating with uncaught exception of type 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)")

})

【问题讨论】:

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


    【解决方案1】:

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

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

    您可以通过使用移动集线器下载使用云逻辑的示例应用来获取示例。

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

    mobile hub diagram

    【讨论】:

    • 谢谢布鲁斯。我已经阅读了您出色的 PDF。这是否意味着我必须实现其他东西才能调用 lambda 函数?
    • 我按照您的示例,将内容添加到 Info.plist。事情更进一步,但仍然出现崩溃,并且此日志:*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is nil. You need to configure Info.plist` 或在使用此方法之前设置defaultServiceConfiguration。'`
    • 我将您的示例与 AWS 给出的示例进行了比较,以试图了解其中的缺失点。他们真的很不一样!
    • Dom,您的代码使用的是 AWSLambda,您不需要使用其他移动集线器帮助程序……但您确实需要使用 AWSCloudLogic 而不是 AWSLambda。 AWSCloudLogic 是 Lambda 的移动集线器包装器。类的 init 确实进行服务配置注册。如果您想使用 AWSLambda 而不是 AWSCLoudLogic,请查看 AWSCloudLogic 中的 init 并进行相同的服务配置设置
    • 很高兴听到您修复了它!请接受答案,让我们知道您认为问题所在。
    猜你喜欢
    • 1970-01-01
    • 2021-09-19
    • 2017-10-13
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 2019-05-12
    • 2019-10-27
    • 2021-12-17
    相关资源
    最近更新 更多