Amazon LEX 返回 iOS Swift 错误
Amazon LEX is returning error with iOS Swift
我正在尝试将 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 一起传递吗?谁能帮我看看这里出了什么问题。提前致谢。
我终于想出了解决办法。问题在于 IAM 许可。您必须在 IAM 控制台中附加权限策略。希望对你有帮助。
似乎与 Cognito 身份池角色关联的 IAM 策略没有 AmazonLexFullAccess 权限。要添加权限,请参阅以下步骤:
去编辑身份池,检查你对未授权和授权的角色。
Select IAM 服务然后搜索角色,然后 select 您分配给未授权和授权的角色。
单击特定角色并附加 AmazonLexFullAccess 策略。
希望这些步骤对您有所帮助。
我正在尝试将 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 一起传递吗?谁能帮我看看这里出了什么问题。提前致谢。
我终于想出了解决办法。问题在于 IAM 许可。您必须在 IAM 控制台中附加权限策略。希望对你有帮助。
似乎与 Cognito 身份池角色关联的 IAM 策略没有 AmazonLexFullAccess 权限。要添加权限,请参阅以下步骤:
去编辑身份池,检查你对未授权和授权的角色。
Select IAM 服务然后搜索角色,然后 select 您分配给未授权和授权的角色。
单击特定角色并附加 AmazonLexFullAccess 策略。
希望这些步骤对您有所帮助。