简体   繁体   中英

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:

在此处输入图像描述

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.

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.

Add region in your.aws/credentials file:

region=us-east-1

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM