Skip to content

Commit d58fda4

Browse files
authored
Merge pull request #175 from alice-byb/feature/add-lambdaRegion-option-to-alpha-config
feat: added lambdaRegion option to config options
2 parents 4477b67 + 7e6bcf6 commit d58fda4

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/adapters/lambda-invocation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import { AbortController } from '@aws-sdk/abort-controller';
1313
const lambdaInvocationAdapter: AlphaAdapter = async (config) => {
1414
const LambdaClass = config.Lambda || Lambda;
1515
const lambdaOptions: LambdaClientConfig = {
16+
region: config.lambdaRegion,
1617
endpoint: config.lambdaEndpoint || process.env.LAMBDA_ENDPOINT,
1718
};
1819

20+
if (config.lambdaRegion) {
21+
// Allow the region to be controlled via config
22+
lambdaOptions.region = config.lambdaRegion;
23+
}
24+
1925
if (config.timeout) {
2026
// Set some low level HTTP client timeout options
2127
// so that the system level resources will be

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AxiosPromise, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2-
import type { Lambda } from '@aws-sdk/client-lambda';
2+
import type { Lambda, LambdaClientConfig } from '@aws-sdk/client-lambda';
33
import type { Context, Handler } from 'aws-lambda';
44
import { SignatureV4CryptoInit, SignatureV4Init } from '@aws-sdk/signature-v4';
55

@@ -26,6 +26,10 @@ export interface AlphaOptions<D = any> extends AxiosRequestConfig<D> {
2626
* (Optional) The AWS endpoint to use when invoking the target Lambda function.
2727
*/
2828
lambdaEndpoint?: string;
29+
/**
30+
* (Optional) The AWS region to use when invoking the target Lambda function.
31+
*/
32+
lambdaRegion?: LambdaClientConfig['region'];
2933
Lambda?: typeof Lambda;
3034
}
3135

test/lambda-invocation.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,24 @@ test('lambdaEndpoint config option is provided to the Lambda client', async () =
524524

525525
expect(FakeLambda).toHaveBeenCalledWith({ endpoint: 'http://test-endpoint' });
526526
});
527+
528+
test('lambdaRegion config option is provided to the Lambda client', async () => {
529+
const alpha = new Alpha('lambda://test-function', {
530+
lambdaRegion: 'ap-southeast-2',
531+
Lambda: FakeLambda,
532+
});
533+
createResponse(mockLambda, {
534+
StatusCode: 200,
535+
Payload: {
536+
body: 'test',
537+
statusCode: 200,
538+
},
539+
});
540+
541+
const response = await alpha.get('/test');
542+
543+
expect(response.data).toBe('test');
544+
expect(response.status).toBe(200);
545+
546+
expect(FakeLambda).toHaveBeenCalledWith({ region: 'ap-southeast-2' });
547+
});

0 commit comments

Comments
 (0)