AWS S3: Credentials missing (aws-sdk v3)

Viewed 373

I am trying to replace S3 aws-sdk v2 with @aws-sdk/client-s3 v3 (The guide I am using). This was working with v2 (putObject, getObject, etc.), but with the changes, I am getting an error saying:

ERROR Error: Uncaught (in promise): Error: Credentialis missing Error: Credentialis missing

This error happens upon load, I am not even calling any of the methods, just initializing the S3 object.

  private readonly s3 = new S3({
    region: environment.AWS.region,
    credentials: fromCognitoIdentityPool({
      client: new CognitoIdentityClient({ region: environment.AWS.region }),
      identityPoolId: environment.AWS.identityPoolId
    })
  })
2 Answers

This issue happens because CognitoIdentityClient is expecting credentials even though they're not required.

private readonly s3 = new S3({
    region: environment.AWS.region,
    credentials: fromCognitoIdentityPool({
      client: new CognitoIdentityClient({
        region: environment.AWS.region,
        credentials: () => Promise.resolve({} as any), // Temporary fix for problem
      }),
      identityPoolId: environment.AWS.identityPoolId
    })
  })

Check if you have the files C:\Users\<user>\.aws\config and C:\Users\<user>\.aws\credentials. The config file should be like:

[default]
aws_access_key_id=ABCDEFGHIJKLMNOPQRST
aws_secret_access_key=ab2sjemdoKDFEJ9?SJDjddd
region=us-west-1

And the credentials file should be like:

[default]
aws_access_key_id=ABCDEFGHIJKLMNOPQRST
aws_secret_access_key=ab2sjemdoKDFEJ9?SJDjddd
Related