How to run AWS SDK with credentials from variables?

Question:

I used environment variables before and it worked fine.

Now I am migrating my config variables into a single file and I have AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID variables containing respective values that are loaded from this file.

I tried this code but receiving an error:

Here is the error

InvalidClientTokenId: The security token included in the request is invalid.

How do I properly inject my keys into the aws sdk calls?

Answer:

Try re-ordering your args so that ACCESS_KEY is the 1st param and SECRET_KEY is the second:

Try adding the region as well:

Leave a Reply