File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "errors"
55 "fmt"
66
7+ "github.com/aws/aws-sdk-go/aws"
78 "github.com/aws/aws-sdk-go/aws/session"
89 kmslib "github.com/aws/aws-sdk-go/service/kms"
910)
@@ -36,3 +37,19 @@ func NewClient(awsProfile string) (Client, error) {
3637 }
3738 return kmslib .New (sess ), nil
3839}
40+
41+ // NewClientWithDefaultCredentials constructs a new kmslib.KMS instance using the default AWS
42+ // credential chain. This is suitable for use in Kubernetes with IRSA (IAM Roles for Service Accounts),
43+ // EC2 instance profiles, or environment variables.
44+ func NewClientWithDefaultCredentials (region string ) (Client , error ) {
45+ if region == "" {
46+ return nil , errors .New ("region is required" )
47+ }
48+ sess , err := session .NewSessionWithOptions (session.Options {
49+ Config : aws.Config {Region : aws .String (region )},
50+ })
51+ if err != nil {
52+ return nil , fmt .Errorf ("failed to create AWS session: %w" , err )
53+ }
54+ return kmslib .New (sess ), nil
55+ }
You can’t perform that action at this time.
0 commit comments