我有一个基本的围棋代码,就像这样.给我的错误是:

2024/02/21 21:49:15 operation error Secrets Manager: GetSecretValue,
  get identity: get credentials: failed to refresh cached credentials,
  no EC2 IMDS role found, operation error ec2imds: GetMetadata,
  request canceled, context deadline exceeded

我使用过Amazon Secure Manager for AWS-rds,我确信凭据是正确的

secretName := "key"
region := "eu-central-1"

config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
    log.Fatal(err)
}

// Create Secrets Manager client
svc := secretsmanager.NewFromConfig(config)

input := &secretsmanager.GetSecretValueInput{
    SecretId:     aws.String(secretName),
    VersionStage: aws.String("AWSCURRENT"), 
}

result, err := svc.GetSecretValue(context.TODO(), input)
if err != nil {
    // For a list of exceptions thrown, see
    // https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
    log.Fatal(err.Error())
}

// Decrypts secret using the associated KMS key.
var secretMap map[string]string
json.Unmarshal([]byte(*result.SecretString), &secretMap)

return secretMap

推荐答案

问题是您没有保存在本地计算机/环境中的AWS凭据.要做到这一点,请执行以下任一步骤:https://wellarchitectedlabs.com/common/documentation/aws_credentials/,然后只需再次运行代码.我建议使用CLI选项,因为这对我来说很容易.

Go相关问答推荐

Kafka消费者在需要时不会暂停

如何存储来自异步Goroutine的返回值列表?

Go中的Slice[:1][0]与Slice[0]

从使用Golang otelmux检测的Otel跟踪中获取trace_id

如何在出现错误时停止从通道读取?

Redis:尽管数据存在,但 rdb.Pipelined 中出现redis:nil错误

使用 OpenTelemetry 统一不同服务的范围

Go test "-run -" 标志执行测试更快

带有前导零的整数参数被 flag.IntVar 解析为八进制

如何在 `hashicorp / terraform-exec` 中将 `ApplyConfig` 传递给 `tf.Apply()`?

Gremlin-Go:树步骤不可序列化

使用 ssh 从私有 gilab 仓库导入一个 go 项目:未知修订

SSH 代理,数据包长度错误

GOLANG:为什么 SetDeadline/SetReadDeadline/SetWriteDeadline 在使用 os.File.Fd() 时对文件不起作用?

如何在切片增长时自动将切片的新元素添加到函数参数

我相信我正确地在 sRGB 和线性 RGB 之间进行了转换,那么为什么深色的结果看起来更糟呢?

go:识别重新定义标志的包

GoLang 遍历 yaml 文件

出于某种原因,Golang (Go) AES CBC 密文被填充了 16 个 0x00 字节

将基本 HTTP AUth 用户/密码凭据存储在 GO 中,无需外部包