playing with a small project on AWS:
- golang app
- RDS/MySQL database
- secret manager
- API gateway and lambda
I'm running the go app locally to verify the interaction with the database, but I can't get it to work with the secret manager.
using this sample code:
func getCreds() {
config, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
log.Fatal(err)
}
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 {
log.Fatal(err.Error())
}
var secretString string = *result.SecretString
log.Printf("pwd: %s", secretString)
}
I'm getting
operation error Secrets Manager: GetSecretValue, exceeded maximum number of attempts, 3, failed to sign request: failed to retrieve credentials: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds
If I understand correctly, I need to add a permission to a user/policy. But where to add this? In the IAM console? Or the secret manager console?
And what should it be?
{
"Version":"2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Principal": {"AWS": "<what to add here>"},
"Resource": "<and here>"
}
]
}