CognitoIdentityClient - 在 iam/security-credentials 中找不到 404

CognitoIdentityClient - 404 not found in iam/security-credentials

我想使用 getOpenIdTokenForDeveloperIdentity.

注册一个 AWS Cognito Identity

以下是我用 CodeIgniter 框架编写的代码:

Awscognitoauth.php

<?php
// <MYPROJECT>/application/controllers/Awscognitoauth.php

defined('BASEPATH') or exit('No direct script access allowed');

class Awscognitoauth extends CI_Controller {

    function getOpenId($userId) {
        $this->load->library('awsauth');
        return $this->awsauth->identity($userId);
    }

}

Awsauth.php

<?php
// <MY PROJECT>/application/libraries/Awsauth.php

defined('BASEPATH') or exit('No direct script access allowed');

require_once APPPATH . "third_party/aws/aws-autoloader.php";

use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;

class Awsauth {

    public function identity($userId) {
        $region = '<my region>';
        $key = '<my key>';
        $secret = '<my secret>';
        $version = 'latest';

        $client = CognitoIdentityClient::factory(array('region' => $region, 'key' => $key, 'secret' => $secret, 'version' => $version));

        $poolId = '<my pool Id>'; // formatted: "<region>:<UUID>"
        $domain = '<my reversed company domain>'; // com.<company...>...

        return $client->GetOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $poolId, 'Logins' => array($domain => $userId))); // https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetOpenIdTokenForDeveloperIdentity.html
    }

}

在 safari 中,我调用控制器 Awscognitoauth 并得到以下错误:

我仔细检查了我的用户角色 here:

什么会导致此 404 Not Found 响应?我以为我的用户有 AdministratorAccess 并且我可以访问任何资源。我错过了什么吗?

哦拍!

我刚刚发现 $key$secret 必须包含在 credentials 中。

所以,Awsauth.php 的最终代码是:

<?php
// <MY PROJECT>/iot.kooltechs.com/application/libraries

defined('BASEPATH') or exit('No direct script access allowed');

require_once APPPATH . "third_party/aws/aws-autoloader.php";

use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;

class Awsauth {

    public function identity($userId) {
        $region = '<my region>';
        $key = '<my key>';
        $secret = '<my secret>';
        $version = 'latest';

        $config = [
            'version' => $version,
            'region' => $region,
            'credentials' => [
                'key' => $key,
                'secret' => $secret
            ]
        ];

        $client = CognitoIdentityClient::factory($config);

        $poolId = '<my pool Id>'; // formatted: "<region>:<UUID>"
        $domain = '<my reversed company domain>'; // com.<company...>...

        return $client->GetOpenIdTokenForDeveloperIdentity(array('IdentityPoolId' => $poolId, 'Logins' => array($domain => $userId)));
    }

}

此致,