1

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();

}
4

1 に答える 1