Amazon RDS Utilities
Using the AWS SDK for Go V2 Amazon RDS Utilities
IAM Authentication
The auth package provides utilities for generating authentication tokens for connecting to Amazon RDS MySQL and PostgreSQL database instances. Using the BuildAuthToken method, you generate a database authorization token by providing the database endpoint, AWS Region, username, and a aws.CredentialProvider implementation that returns IAM credentials with permission to connect to the database using IAM database authentication. To learn more about configuring Amazon RDS with IAM authentication see the following Amazon RDS Developer Guide resources:
- Enabling and disabling IAM database authentication
- Creating and using an IAM policy for IAM database access
- Creating a database account using IAM authentication
The following examples shows how to generate an authentication token to connect to an Amazon RDS database:
import "context"
import "github.com/aws/aws-sdk-go-v2/config"
import "github.com/aws/aws-sdk-go-v2/feature/rds/auth"
// ...
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
panic("configuration error: " + err.Error())
}
authenticationToken, err := auth.BuildAuthToken(
context.TODO(),
"mydb.123456789012.us-east-1.rds.amazonaws.com:3306", // Database Endpoint (With Port)
"us-east-1", // AWS Region
"jane_doe", // Database Account
cfg.Credentials,
)
if err != nil {
panic("failed to create authentication token: " + err.Error())
}
Last modified February 14, 2023: Update grammar, spelling in rds.md (#1970) (93c2cd9dca)