Skip to content

Commit b95a580

Browse files
authored
Merge pull request #46 from gruntwork-io/feature/add-kms-helpers
add GetDedicatedTestKeyArn
2 parents 2305fe3 + e00e8a2 commit b95a580

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

aws/kms.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package aws
33
import (
44
"github.com/aws/aws-sdk-go/aws/session"
55
"github.com/aws/aws-sdk-go/service/kms"
6+
"github.com/aws/aws-sdk-go/aws"
67
)
78

89
func CreateKmsClient(awsRegion string) (*kms.KMS, error) {
@@ -13,3 +14,24 @@ func CreateKmsClient(awsRegion string) (*kms.KMS, error) {
1314

1415
return kms.New(session.New(), awsConfig), nil
1516
}
17+
18+
// This exists because KMS keys cost $1/mo for each one created. In our automated tests, we often run 100s times in,
19+
// especially during inital development when debugging. Rather than create a new key each time we run a test and incurring
20+
// the $1 charge, a dedicated key with the alias 'dedicated-test-key' has been created in each region. This method allows
21+
// this key to be retrieved and used for testing purposes.
22+
func GetDedicatedTestKeyArn(awsRegion string) (string, error) {
23+
kmsClient, err := CreateKmsClient(awsRegion)
24+
if err != nil {
25+
return "", err
26+
}
27+
28+
result, err := kmsClient.DescribeKey(&kms.DescribeKeyInput{
29+
KeyId: aws.String("alias/dedicated-test-key"),
30+
})
31+
32+
if err != nil {
33+
return "", err
34+
}
35+
36+
return *result.KeyMetadata.Arn, nil
37+
}

0 commit comments

Comments
 (0)