在Elastic beanstalk中的docker容器中运行我的应用程序时,我注意到此错误。提取用户和登录操作可以正常工作,但是尝试创建新用户会引发此错误。
针对同一个Cognito实例在本地进行开发不会发生此问题。我认为这与从附加到 flex beantalk实例的IAM角色中获取权限有关。
flex beantalk实例的IAM实例配置文件附加了AmazonCognitoPowerUser策略。这与我用于本地开发的用户所附加的策略相同
堆栈跟踪:
System.IO.InvalidDataException: Cannot determine protocol
at Amazon.Runtime.Internal.Signer.SignRequest(IRequestContext requestContext)
at Amazon.Runtime.Internal.Signer.PreInvoke(IExecutionContext executionContext)
at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()
错误出现的相关代码:
private static AmazonCognitoIdentityProviderClient Client => new AmazonCognitoIdentityProviderClient(Amazon.RegionEndpoint.APSoutheast2);
var signUpRequest = new SignUpRequest
{
ClientId = AWSCognitoClientId,
Username = email,
Password = password
};
await Client.SignUpAsync(signUpRequest);
我不确定这是不是SDK中的错误或 flex beantalk实例的配置错误
最佳答案
我可以通过使用AmazonCognitoIdentityProviderClient
实例化AnonymousAWSCredentials
来解决它,如此处建议的:https://github.com/aws/aws-sdk-net/issues/937#issuecomment-415454184。
var forgotPasswordRequest = new ForgotPasswordRequest
{
// ...
};
using (var identityProvider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials()))
{
return identityProvider.ForgotPasswordAsync(forgotPasswordRequest);
}
我正在使用Cognito的
ForgotPassword
/ ForgotPasswordAsync
.NET SDK遇到此问题。identityProvider.ForgotPasswordAsync(forgotPasswordRequest);
它在抛出:
System.IO.InvalidDataException: Cannot determine protocol
at Amazon.Runtime.Internal.Signer.SignRequest(IRequestContext requestContext)
at Amazon.Runtime.Internal.Signer.PreInvoke(IExecutionContext executionContext)
at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
...