【问题标题】:'User not found exception' while accessing AWS API gateway访问 AWS API 网关时出现“用户未找到异常”
【发布时间】:2017-06-15 12:50:00
【问题描述】:

访问 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 中启用日志记录?您是否使用了测试调用功能来确保基本功能?
  • 如何在 API 中检查日志功能?
  • 并且角色策略中没有“执行:调用”功能。是不是在制造问题。

标签: android amazon-web-services aws-api-gateway google-authentication aws-cognito


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2021-05-05
    • 2019-06-11
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多