-1

I am using aws-go sdk using static creds I am able to connect using

config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(awsAccesstKey, awsSecretKey, "")),

is there anyway using nodeIAM role, by which we can connect to AWS?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Are you asking how to connect to AWS by using an IAM Role? You can request to `AssumeRole()`, but to do this you must first authenticate as an IAM User to confirm that you are permitted to assume the role. Is there another way that you wish to authenticate to AWS to prove that you are entitled to use the IAM Role? (eg Federated sign-in, SSO, or a Username/Password in a database?) – John Rotenstein Jul 12 '22 at 08:09

1 Answers1

0

The documentation explains how to configure the SDK, including credentials:

cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
  log.Fatalf("failed to load configuration, %v", err)
}

From the link above:

When you initialize an aws.Config instance using config.LoadDefaultConfig, the SDK uses its default credential chain to find AWS credentials. This default credential chain looks for credentials in the following order:

  • Environment variables.
    • Static Credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN)
    • Web Identity Token (AWS_WEB_IDENTITY_TOKEN_FILE)
  • Shared configuration files.
    • SDK defaults to credentials file under .aws folder that is placed in the home folder on your computer.
    • SDK defaults to config file under .aws folder that is placed in the home folder on your computer.
  • If your application uses an ECS task definition or RunTask API operation, IAM role for tasks.
  • If your application is running on an Amazon EC2 instance, IAM role for Amazon EC2.

The SDK detects and uses the built-in providers automatically, without requiring manual configurations. For example, if you use IAM roles for Amazon EC2 instances, your applications automatically use the instance’s credentials. You don’t need to manually configure credentials in your application.

gshpychka
  • 8,523
  • 1
  • 11
  • 31