0

我正在尝试将 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
    }

视图控制器代码:

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)")
    }

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

4

2 回答 2

0

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

于 2017-06-14T09:43:01.287 回答
0

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

  1. 转到编辑身份池,检查未授权和授权的角色。

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

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

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

于 2019-01-15T06:29:36.720 回答