3

在 Elastic beanstalk 的 docker 容器中运行我的应用程序时,我注意到了这个错误。获取用户和登录操作工作正常,但尝试创建新用户会引发此错误。

针对同一个 Cognito 实例进行本地开发,不会发生此问题。我认为这与从附加到弹性 beanstalk 实例的 IAM 角色中检索权限有关。

弹性 beanstalk 实例的 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 中的错误或弹性 beanstalk 实例的错误配置

4

1 回答 1

0

AmazonCognitoIdentityProviderClient我可以通过实例化with来解决它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)
...
于 2018-10-01T20:24:07.017 回答