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

huangapple go评论90阅读模式
英文:

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

问题

我正在尝试从我的本地机器创建Amazon SQS,并遇到以下错误:

尝试创建队列时出错:NoCredentialProviders: 链中没有有效的提供程序。已弃用。
有关详细信息,请参阅aws.Config.CredentialsChainVerboseErrors。

我所做的:

步骤1:
我在.aws/credentials文件中设置了我的凭证。

[default]
aws_access_key_id = TestAccessKey
aws_secret_access_key = TestSecretAccessKey

步骤2:
我的Go语言代码如下:

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("初始化新会话时出错:%v", err)
		return
	}

	queueName := "my-new-queue"
	createRes, err := CreateQueue(sess, queueName)
	if err != nil {
		fmt.Printf("尝试创建队列时出错:%v", err)
		return
	}

	fmt.Println("创建了一个新队列,URL为:" + *createRes.QueueUrl)
}

步骤3:

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:

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

答案1

得分: 1

尝试按照以下方式在**共享凭证文件(.aws/credentials)**中更新配置文件:

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

我刚刚在最后添加了region。

英文:

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.

答案2

得分: 1

要验证您的CLI会话是否配置了正确的AWS凭据,请运行以下命令:aws sts get-caller-identity。该命令将显示使用的配置文件。如果这个命令正常工作,那么您可以运行任何简单的AWS命令,比如S3.getBuckets(),以验证开发环境是否正确设置。

这两个解决方案应该足够提供足够的信息,以找出问题所在。

英文:

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.

huangapple
  • 本文由 发表于 2022年2月1日 16:22:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/70937391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定