【问题标题】:Amazon LEX is returning error with iOS SwiftAmazon LEX 使用 iOS Swift 返回错误
【发布时间】:2019-01-15 14:29:36
【问题描述】:

我正在尝试将 Amazon LEX 集成到我的应用程序中。最初我添加了 Amazon cognito,然后我得到了 Cognito Id。接下来,当我尝试与 LEX 通信时,返回一个错误,如下所示

Error Domain=com.amazonaws.AWSLexErrorDomain Code=0 "null" UserInfo={NSLocalizedDescription=null, NSLocalizedFailureReason=AccessDeniedException:http://internal.amazon.com/coral/com.amazon.coral.service/}

AppDelegate 代码:

{
        // Override point for customization after application launch.


        AWSDDLog.sharedInstance.logLevel = .verbose
        let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: “given the Id”)
        let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
        AWSServiceManager.default().defaultServiceConfiguration = configuration


        credentialProvider.getIdentityId().continueWith(block: { (task) -> AnyObject? in

            if (task.error != nil)
            {
                print("Error: " + task.error!.localizedDescription)
            }
            else
            {
                let cognitoId = task.result!
                print("Cognito Id is, \(cognitoId)")
            }

            return task

        })

        let chatConfig = AWSLexInteractionKitConfig.defaultInteractionKitConfig(withBotName: "BookTrip", botAlias: "Chatting")
        AWSLexInteractionKit.register(with: configuration!, interactionKitConfiguration: chatConfig, forKey: "AWSLexVoiceButton")

        chatConfig.autoPlayback = false
        //AWSLexInteractionKit.register(with: configuration!, interactionKitConfiguration: chatConfig, forKey: "chatConfig")
    return true
    }

viewController 代码:

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

       (self.voiceButton)?.delegate = self
   // (self.voiceButton as AWSLexVoiceButton).delegate = self


    }

    func voiceButton(_ button: AWSLexVoiceButton, on response: AWSLexVoiceButtonResponse) {
        DispatchQueue.main.async(execute: {
            // `inputranscript` is the transcript of the voice input to the operation
            print("Input Transcript: \(String(describing: response.inputTranscript))")
            if let inputTranscript = response.inputTranscript {
                self.input.text = "\"\(inputTranscript)\""
            }
            print("on text output \(String(describing: response.outputText))")
            self.output.text = response.outputText
        })
    }

    public func voiceButton(_ button: AWSLexVoiceButton, onError error: Error) {
        print("error \(error)")
    }

我是否需要将 cognito Id 与 LEX 一起传递。谁能帮我这里有什么问题。提前致谢。

【问题讨论】:

    标签: amazon-web-services swift3 xamarin.ios amazon-cognito amazon-lex


    【解决方案1】:

    我终于找到了解决方案。问题在于 IAM 许可。您必须在 IAM 控制台中附加权限策略。希望对您有所帮助。

    【讨论】:

    • 哪个权限?卡在同一个地方
    • 控制台中的 IAM 权限。 i,e 登录亚马逊门户并为您的机器人添加 IAM 权限
    【解决方案2】:

    与 Cognito 身份池的角色关联的 IAM 策略似乎没有 AmazonLexFullAccess 权限。要添加权限,请参见以下步骤:

    1. 去编辑身份池,检查你对未授权和授权的角色。

    2. 选择 IAM 服务,然后搜索角色,然后选择您分配给取消授权和授权的角色。

    3. 单击特定角色并附加 AmazonLexFullAccess 策略。

    希望这些步骤对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2017-02-16
      • 1970-01-01
      相关资源
      最近更新 更多