'Amazon SQS:: Got an error while trying to create queue: NoCredentialProviders: no valid providers in chain. Deprecated

I am trying to create Amazon SQS from my local machine and facing errors like

Got an error while trying to create queue: NoCredentialProviders: no valid providers in chain. Deprecated. 
For verbose messaging see aws.Config.CredentialsChainVerboseErrors

What I did:

Step-1: I have set up my credentials in .aws/credentials file

[default]
aws_access_key_id = TestAccessKey
aws_secret_access_key = TestSecretAccessKey

Step-2: My code in go lang like below

package main

import (
    "fmt"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/sqs"
)

func CreateQueue(sess *session.Session, queueName string) (*sqs.CreateQueueOutput, error) {
    sqsClient := sqs.New(sess)
    result, err := sqsClient.CreateQueue(&sqs.CreateQueueInput{
        QueueName: &queueName,
        Attributes: map[string]*string{
            "DelaySeconds":      aws.String("0"),
            "VisibilityTimeout": aws.String("60"),
        },
    })

    if err != nil {
        return nil, err
    }

    return result, nil
}

func main() {
    sess, err := session.NewSessionWithOptions(session.Options{
        Profile: "default",
        Config: aws.Config{
            Region: aws.String("us-east-1"),
        },
    })

    if err != nil {
        fmt.Printf("Failed to initialize new session: %v", err)
        return
    }

    queueName := "my-new-queue"
    createRes, err := CreateQueue(sess, queueName)
    if err != nil {
        fmt.Printf("Got an error while trying to create queue: %v", err)
        return
    }

    fmt.Println("Created a new queue with url: " + *createRes.QueueUrl)
}

Step-3:

enter image description here



Solution 1:[1]

Try updating profile in Shared Credential File (.aws/credentials) as below:

[default]
aws_access_key_id=TestAccessKey
aws_secret_access_key=TestSecretAccessKey
region=us-east-1

I just added region at the end.

Solution 2:[2]

To verify if your CLI session has correct AWS credentials configured run this command aws sts get-caller-identity This command will show which profile is used. If this works fine then you can run any simple AWS commands something like S3.getBuckets() to verify if the dev environment is setup correctly.

These 2 solutions should give you enough input to figure out what's wrong.

Solution 3:[3]

Add region in your .aws/credentials file:

region=us-east-1

see the region in aws console in which you have created the sqs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ankush Jain
Solution 2 Hussain Mansoor
Solution 3 Anushil Kumar