在Swift上实例化AWSLambdaInvoker时,服务配置为“ nil”

时间:2018-09-06 14:21:51

标签: ios swift amazon-web-services aws-lambda

我正在尝试通过iOS应用程序实现lambda函数。我按照本教程表单AWS上的所有步骤操作:https://docs.aws.amazon.com/aws-mobile/latest/developerguide/how-to-ios-lambda.html

但是当我添加以下行时:

let lambdaInvoker = AWSLambdaInvoker.default()

它抛出此错误:

*** 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.'

我将awsconfiguration.json文件添加到项目中,内容如下:

{
"Version": "1.0",
"CredentialsProvider": {
    "CognitoIdentity": {
        "Default": {
            "PoolId": "us-east-1:05aab771-99b5-4a9b-8448-de92fe86ba56",
            "Region": "us-east-1"
        }
    }
},
"IdentityManager" : {
  "Default" : {

  }
}
}

该应用程序在导入AWSLambda和mobileClient时运行良好,并且能够使用Cognito验证凭据(我收到“欢迎使用AWS”消息)

任何想法?

1 个答案:

答案 0 :(得分:1)

您将必须更新awsconfiguraiton.json文件以获取有关LambdaInvoker的信息,以便它可以加载默认服务配置的配置。更新后的文件应如下所示:

{
  "Version": "1.0",
  "CredentialsProvider": {
    "CognitoIdentity": {
        "Default": {
            "PoolId": "us-east-1:05aab771-99b5-4a9b-8448-de92fe86ba56",
            "Region": "us-east-1"
        }
    }
  },
  "IdentityManager" : {
    "Default" : {

    }
  },
  "LambdaInvoker" : {
    "Default" : {
         "Region": "us-east-1"
    }
  }
}