diff --git a/canned/dynamodb.go b/canned/dynamodb.go index 7b8d9ad..9b7c222 100644 --- a/canned/dynamodb.go +++ b/canned/dynamodb.go @@ -50,7 +50,7 @@ func NewDynamoDB(ctx context.Context) (*DynamoDB, error) { host, _ := container.Host(ctx) port, _ := container.MappedPort(ctx, "8000") - accessKey, secretKey, region := "awsaccesskey", "awssecretkey", "ap-southeast-1" + accessKey, secretKey, region := getAWSConfig() endpoint := fmt.Sprintf("http://%s:%s", host, port.Port()) dynamoClient, err := newDynamoClient(endpoint, accessKey, secretKey, region) diff --git a/canned/localstack.go b/canned/localstack.go index 0692639..0111840 100644 --- a/canned/localstack.go +++ b/canned/localstack.go @@ -48,7 +48,7 @@ func NewLocalstack(ctx context.Context) (*Localstack, error) { host, _ := container.Host(ctx) port, _ := container.MappedPort(ctx, "4566") - accessKey, secretKey, region := "awsaccesskey", "awssecretkey", "ap-southeast-1" + accessKey, secretKey, region := getAWSConfig() endpoint := fmt.Sprintf("http://%s:%s", host, port.Port()) awsSession, err := newAWSSession(accessKey, secretKey, endpoint, region) diff --git a/canned/minio.go b/canned/minio.go index 14b41eb..8681020 100644 --- a/canned/minio.go +++ b/canned/minio.go @@ -29,7 +29,7 @@ type Minio struct { func NewMinio(ctx context.Context) (*Minio, error) { os.Setenv("TC_HOST", "localhost") - accessKey, secretKey, region := "awsaccesskey", "awssecretkey", "ap-southeast-1" + accessKey, secretKey, region := getAWSConfig() req := testcontainers.ContainerRequest{ Image: getEnvString("MINIO_CONTAINER_IMAGE", "minio/minio:RELEASE.2023-05-18T00-05-36Z"), diff --git a/canned/sqs.go b/canned/sqs.go index 3d768d5..19101ea 100644 --- a/canned/sqs.go +++ b/canned/sqs.go @@ -50,7 +50,7 @@ func NewSQS(ctx context.Context) (*SQS, error) { host, _ := container.Host(ctx) port, _ := container.MappedPort(ctx, "9324") - accessKey, secretKey, region := "awsaccesskey", "awssecretkey", "ap-southeast-1" + accessKey, secretKey, region := getAWSConfig() endpoint := fmt.Sprintf("http://%s:%s", host, port.Port()) sqsClient, err := newSQSClient(endpoint, accessKey, secretKey, region) diff --git a/canned/util.go b/canned/util.go index b093d8b..642b7e4 100644 --- a/canned/util.go +++ b/canned/util.go @@ -25,6 +25,14 @@ func getEnvString(variable string, defaultValue string) string { return val } +func getAWSConfig() (string, string, string) { + accessKey := getEnvString("AWS_ACCESS_KEY_ID", "awsaccesskey") + secretKey := getEnvString("AWS_SECRET_ACCESS_KEY", "awssecretkey") + region := getEnvString("AWS_REGION", "ap-southeast-1") + + return accessKey, secretKey, region +} + func getBasicAuth() string { username := os.Getenv("CONTAINER_REGISTRY_USERNAME") password := os.Getenv("CONTAINER_REGISTRY_PASSWORD")