When using Cognito credentials with AWS in a browser (javascript), keep getting “missing credentials” error

Question:

I’m attempting to upload a file to an S3 bucket of mine from a web browser using AWS’ JavaScript SDK. My code looks like this:

However, whenever it reaches the putObject command, I keep getting an error back from AWS:

“Error: Missing credentials in config {message: “Missing credentials in config”, code: “CredentialsError”…”

I’m sure I’m missing something simple and stupid here, but I can’t figure out what for the life of me. (I get a different error when I try to just hardcode a bogus secret key in or something, so I’m pretty sure it has something to do with the way I’m trying to set up cognito credentials.)

Answer:

Turns out that after debugging the JavaScript AWS SDK, the problem was that I wasn’t setting the region before setting the credentials… And for some reason, I need to use the update method, as well. I think this seems like a bug with the SDK, but the following setup of AWS.config fixed my problem:

Leave a Reply