访问 AWS API 网关时'User not found exception'



访问 AWS API 网关时,我收到以下错误:

com.amazonaws.mobileconnectors.apigateway.ApiClientException:  {"errorMessage":"[NotFoundException]:'User not found: us-east-1:fb********6a'"} (Service: MyClient; Status Code: 500; Error Code: null; Request ID: 20*****e97)
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.handleResponse(ApiClientHandler.java:267)
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at com.amazonaws.mobileconnectors.apigateway.ApiClientHandler.invoke(ApiClientHandler.java:94)
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at java.lang.reflect.Proxy.invoke(Proxy.java:393)
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at $Proxy1.apiTeamRolesGet()
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at com.myaws.android.MainActivity.performAws(MainActivity.java:323)
01-30 16:21:59.367 24265-24598/com.myaws.android W/System.err:     at com.myaws.android.MainActivity.access$000(MainActivity.java:55)
01-30 16:21:59.368 24265-24598/com.myaws.android W/System.err:     at com.myaws.android.MainActivity$1.run(MainActivity.java:213)


这是我的代码,我如何访问它们。

调用方法时onClick()函数

@Override
public void onClick(View v) {
    new Thread() {
        @Override
        public void run() {
            try {
                performAws();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}

以下是performAws()方法:

private void performAws() {
    try {
        AccountManager am = AccountManager.get(MainActivity.this);
        Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
        String clientId = GOOGLE_CLIENT_ID;
        String scope = "audience:server:client_id:" + clientId;
        //Retrieve the google token
        String token = GoogleAuthUtil.getToken(getApplicationContext(), accounts[0].name, scope);
        //Set the google token in map
        Map<String, String> logins = new HashMap<>();
        logins.put("accounts.google.com", token);
        //Initialize amazon cognito credentials provider
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                MainActivity.this, // Context
                IDENTITY_POOL_ID,
                Regions.US_EAST_1 // Region
        );
        //Set the google credentials
        credentialsProvider.setLogins(logins);
        //retrieve amazon cognito id
        String cognitoId = credentialsProvider.getIdentityId();
        Log.d("MainActivity", "cognitoId = " + cognitoId);
        ApiClientFactory factory = new ApiClientFactory()
                .credentialsProvider(credentialsProvider)
                .region("us-east-1")
                .apiKey(cognitoId);

        final MyClient myClient = factory.build((MyClient .class));
        myClient .apiTeamRolesGet();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

这是我MyClient类文件:

@com.amazonaws.mobileconnectors.apigateway.annotation.Service(endpoint = "https://abc.xyz.com")
public interface MyClient{
    /**
    * @return void
    */
    @com.amazonaws.mobileconnectors.apigateway.annotation.Operation(path = "/api/teamRoles", method = "GET")
        void apiTeamRolesGet();
}

您可以使用测试调用功能独立于客户端代码测试 api:

http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-test-method.html

http://docs.aws.amazon.com/cli/latest/reference/apigateway/test-invoke-method.html

您还可以启用日志记录以获取有关失败的详细信息:

https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudwatch-logs/

相关内容

最新更新