AWS Go SDK not finding the credentials file at C:/###/.aws/credentials


I am using Amazon Kinesis and the Go SDK for AWS, but I’m getting an error.

This is my code:

package main

import (

    _kinesis ""

func main() {
    session, err := session.NewSession(&aws.Config{
        Region: aws.String("us-east-1"),


    kinesis := _kinesis.New(session)

    laugh := strings.Builder{}
    laughingSounds := []string{"haha", "hoho", "hehe", "hehehe", "*snicker*"}

    for i := 0; i < 10; i++ {

    _, err = kinesis.PutRecord(&_kinesis.PutRecordInput{
        Data:         []byte(laugh.String()),
        PartitionKey: aws.String("laughs"),
        StreamName:   aws.String("laughs"),


func handleErr(err error) {
      if err != nil {

When I run this, I get an error:

panic: UnrecognizedClientException: The security token included in the request is invalid.
        status code: 400, request id: dc139793-cd38-fb30-86a3-f92b6410e1c7

goroutine 1 [running]:
        C:/Users/####/----/main.go:34 +0x3ac
exit status 2

I have run aws configure:

$ aws configure
AWS Access Key ID [None]:  ####
AWS Secret Access Key [None]: ####
Default region name [None]: us-east-1
Default output format [None]: 

and the C:/users/####/.aws/credentials file is created with the correct configuration. But my program still wouldn’t execute successfully.

I tried to set an environment variable, but to no avail.

$ $env:aws_access_key_id="####"

Version info:

$ pwsh -v
PowerShell 7.2.2
$ aws -v
aws-cli/2.4.27 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

OS: Windows 11


I found the answer in GoDoc, I just had to change a config setting and use NewSessionWithOptions:

session, err := session.NewSessionWithOptions(session.Options{
    Config: aws.Config{
        Region: aws.String("<your region>"),
    }, SharedConfigState: session.SharedConfigEnable,

Be sure to run aws configure with the correct credentials (or even just manually create the ~/.aws/credentials file), or this won’t work.

Answered By – DaCool1

Answer Checked By – Timothy Miller (GoLangFix Admin)

Leave a Reply

Your email address will not be published.