提供的令牌格式不正确或无效



>latest显示所有 S3 存储桶文件,但是当我上传文件时,会生成错误。

我有 ARN 和实例配置文件。

use AwsCredentialsCredentialProvider;
use AwsCredentialsInstanceProfileProvider;
use AwsCredentialsAssumeRoleCredentialProvider;
use AwsS3S3Client;
use AwsStsStsClient;
$profile = new InstanceProfileProvider();
$ARN = ""; // MY ARN
$sessionName = "s3-access-example";
$assumeRoleCredentials = new AssumeRoleCredentialProvider([
    'client' => new StsClient([
        'region' => "ap-east-1",
        'version' => "latest",
        'credentials' => $profile
    ]),
    'assume_role_params' => [
        'RoleArn' => $ARN,
        'RoleSessionName' => $sessionName,
    ],
]);
$provider = CredentialProvider::memoize($assumeRoleCredentials);
$this->s3hd = S3Client::factory([
    'credentials' => $provider,
    'version' => "latest",
    'region' => "ap-east-1"
]);
public function upload($name, $file, $type, $Bucket = false)
{
    if (! $Bucket) {
        $Bucket = $this->bucket;
    }
    $result = $this->s3hd->putObject([
        'Bucket' => $Bucket,
        'Key' => $name,
        'SourceFile' => $file,
        'ContentType' => $type,
        'ACL' => 'public-read'
    ]);
    $this->s3hd->waitUntil('ObjectExists', [
        'Bucket' => $Bucket,
        'Key' => $name
    ]);
    return $result;
}

消息:在error file url here上执行"放置对象"时出错;AWS HTTP 错误:客户端错误:PUT error file url here导致 400 错误请求的响应:无效令牌提供的令牌格式不正确或其他(截断...无效令牌(客户端(:提供的令牌格式不正确或无效。- 无效令牌提供的令牌格式不正确或无效。

就我而言。我正在尝试通过 CLI。

  1. 我通过运行来配置 AWS CLI
aws configure
  1. ~/.aws/credentials里面,寻找session_token。如果你有session_token.然后更新它。否则,请删除session_token,然后重试。

瞧,它奏效了!

您收到此错误是因为默认情况下未启用香港 (ap-east-1(。如果您具有正确的权限,则需要在 AWS 控制台中启用它,然后重试。

有关如何执行此操作的说明,请参阅 AWS 文档。

我正在使用s3cmd,基于上述答案,我能够通过删除.s3cmd文件并重新配置(s3cmd --configure(来解决,从而清除了access_token

diff .s3cfg previous_s3cmd
< access_token =
---
> access_token = vkp1Jfetc...

还增加了块大小:

< recv_chunk = 65536
---
> recv_chunk = 4096
< send_chunk = 65536
---
> send_chunk = 4096

我想我以前选择了https请求,而不是(当前(默认值:

< use_https = True
---
> use_https = False

成功

Success. Your access key and secret key worked fine :-)
Now verifying that encryption works...
Success. Encryption and decryption worked fine :-)

就我而言,我必须更新 aws 配置文件。您可以按照以下步骤操作。在本地命令行终端中:

打开 ~./aws

打开凭证文件并更新以下 3 个条目的值:

aws_access_key_id

aws_secret_access_key

aws_session_token

您可以从 AWS 控制台获取这些值。希望对您有所帮助!!

相关内容

  • 没有找到相关文章

最新更新