88 "github.com/aws/aws-sdk-go-v2/aws"
99 "github.com/aws/aws-sdk-go-v2/service/lambda"
1010 "github.com/aws/aws-sdk-go-v2/service/lambda/types"
11+
1112 "go.temporal.io/auto-scaled-workers/wci/client"
1213 "go.temporal.io/auto-scaled-workers/wci/workflow/iface"
1314 "go.temporal.io/server/common/dynamicconfig"
@@ -24,6 +25,11 @@ type awsLambdaComputeProvider struct {
2425 requireRoleAndExternalID bool
2526}
2627
28+ type lambdaAPI interface {
29+ Invoke (ctx context.Context , params * lambda.InvokeInput , optFns ... func (* lambda.Options )) (* lambda.InvokeOutput , error )
30+ GetFunction (ctx context.Context , params * lambda.GetFunctionInput , optFns ... func (* lambda.Options )) (* lambda.GetFunctionOutput , error )
31+ }
32+
2733func init () {
2834 RegisterComputeProvider (iface .ComputeProviderTypeAWSLambda , NewAWSLambdaComputeProvider )
2935}
@@ -112,8 +118,21 @@ func (p *awsLambdaComputeProvider) checkExternalID(ctx context.Context, cfg Comp
112118 return verifyExternalIDEnforcedFn (ctx , region , roleARN , p .intermediaryRoles )
113119}
114120
115- // getLambdaClientAndARN builds AWS config (including intermediary and config role assumption), returns a Lambda client and the function ARN.
116- func (p * awsLambdaComputeProvider ) getLambdaClientAndARN (ctx context.Context , cfg ComputeProviderConfig ) (* lambda.Client , string , error ) {
121+ // newLambdaClientFn builds the AWS config (including intermediary and config role
122+ // assumption) and constructs a Lambda client. It is a package-level variable so tests
123+ // can swap it for a mock without reaching AWS.
124+ var newLambdaClientFn = newLambdaClient
125+
126+ func newLambdaClient (ctx context.Context , region , roleARN string , externalID * string , intermediaryRoles [][]client.AWSIAMRoleRequest ) (lambdaAPI , error ) {
127+ awsConfig , err := buildAWSConfig (ctx , region , roleARN , externalID , intermediaryRoles )
128+ if err != nil {
129+ return nil , err
130+ }
131+ return lambda .NewFromConfig (awsConfig ), nil
132+ }
133+
134+ // getLambdaClientAndARN validates the config and returns a Lambda client and the function ARN.
135+ func (p * awsLambdaComputeProvider ) getLambdaClientAndARN (ctx context.Context , cfg ComputeProviderConfig ) (lambdaAPI , string , error ) {
117136 arn , ok := cfg [configAWSLambdaARN ].(string )
118137 if ! ok || arn == "" {
119138 return nil , "" , fmt .Errorf ("AWS Lambda Function ARN not found or invalid" )
@@ -136,10 +155,10 @@ func (p *awsLambdaComputeProvider) getLambdaClientAndARN(ctx context.Context, cf
136155 roleExternalID = & eid
137156 }
138157
139- awsConfig , err := buildAWSConfig (ctx , region , roleARN , roleExternalID , p .intermediaryRoles )
158+ lambdaClient , err := newLambdaClientFn (ctx , region , roleARN , roleExternalID , p .intermediaryRoles )
140159 if err != nil {
141160 return nil , "" , err
142161 }
143162
144- return lambda . NewFromConfig ( awsConfig ) , arn , nil
163+ return lambdaClient , arn , nil
145164}
0 commit comments