AWS CredentialsError S3: не удалось загрузить учетные данные из CognitoIdentityCredentials - PullRequest
0 голосов
/ 07 апреля 2020

AWS CredentialsError S3: Не удалось загрузить учетные данные из CognitoIdentityCredentials

Я использую зарегистрированный AWS Cognito. После регистрации я пытаюсь загрузить изображение в корзину s3. Я не хочу передавать свой accessKey и accessId в коде. Что я делаю -

Я использую Angular 8 +

import * as AWS from 'aws-sdk';


AWS.config.update({
      region: Config.settings.userPool.region,
      credentials: new AWS.CognitoIdentityCredentials({
        IdentityPoolId: Config.settings.userPool.identityPoolId,
      }),
    });

const params = {
      Bucket: Config.settings.buckets3.imageS3,
      Key: this.FOLDER + file.name,
      Body: file,
      ContentEncoding: Config.settings.buckets3.contentEncoding,
      ContentDisposition: Config.settings.buckets3.contentDisposition,
      ContentType: Config.settings.buckets3.contentType,
    };
    const s3Bucket = new AWS.S3({});

return new Promise((resolve, reject) => {
      s3Bucket.upload(params, function (err, data) {
        if (err) {
          const print = console.log;
          print('There was an error uploading your file: ', err);
          reject(err);
        } else {
          const print = console.log;
          print('Successfully uploaded file.', data);
          data.Location = data.Location.replace('s3.ap-south-1.amazonaws.com/', '');
          resolve(data);
        }
    });

Цель тестирования - для проверки правильности учетных данных

AWS.config.getCredentials(function (err) {
      if (!err) {
        console.log(AWS.config.credentials.accessKeyId);
      } else {
        console.log(err);
      }
    });
...