Skip to content

Commit 9f68b87

Browse files
committed
Wip
1 parent 3ff7d6f commit 9f68b87

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

keystore/kms/client.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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+
}

0 commit comments

Comments
 (0)