@@ -12,7 +12,7 @@ import getPort from 'get-port';
12
12
import http from 'http' ;
13
13
import { URL } from 'url' ;
14
14
15
- import { SAMTemplate } from './types' ;
15
+ import { SAMLocalLambadCLIOptions , SAMTemplate } from './types' ;
16
16
import { getLocalIpAddressFromHost , unzipToLocation } from './utils' ;
17
17
import { createSAMLocal , SAMLocal } from './SAMLocal' ;
18
18
@@ -28,6 +28,7 @@ interface Props {
28
28
runtime ?: 'nodejs12.x' | 'nodejs14.x' ;
29
29
onData ?: ( data : any ) => void ;
30
30
onError ?: ( data : any ) => void ;
31
+ cliOptions ?: SAMLocalLambadCLIOptions ;
31
32
}
32
33
33
34
interface SendRequestEventProps {
@@ -48,6 +49,7 @@ export async function generateProxySAM({
48
49
runtime = 'nodejs12.x' ,
49
50
onData,
50
51
onError,
52
+ cliOptions= { } ,
51
53
} : Props ) : Promise < SAM > {
52
54
const _tmpDir = tmpDir ( { unsafeCleanup : true } ) ;
53
55
const workdir = _tmpDir . name ;
@@ -82,8 +84,10 @@ export async function generateProxySAM({
82
84
fs . writeFileSync ( path . join ( workdir , 'template.yml' ) , yaml ( SAMTemplate ) ) ;
83
85
84
86
let SAM : SAMLocal ;
87
+ let host : string ;
85
88
let port : number ;
86
89
let client : AWSLambda ;
90
+ let region : string ;
87
91
let portProxyConfig : number ;
88
92
// Simple HTTP server to serve the proxy config
89
93
// https://stackoverflow.com/a/44188852/831465
@@ -95,14 +99,14 @@ export async function generateProxySAM({
95
99
async function start ( ) {
96
100
// Initialize SAM
97
101
port = await getPort ( ) ;
98
- SAM = await createSAMLocal ( 'sdk' , workdir , port , {
102
+ host = cliOptions . host || '127.0.0.1'
103
+ region = cliOptions . region || 'local'
104
+ SAM = await createSAMLocal ( 'sdk' , workdir , {
99
105
onData,
100
106
onError,
107
+ cliOptions : { ...cliOptions , port, host, region } ,
101
108
} ) ;
102
- client = new AWSLambda ( {
103
- endpoint : `http://localhost:${ port } ` ,
104
- region : 'local' ,
105
- } ) ;
109
+ client = new AWSLambda ( { endpoint : `http://${ host } :${ port } ` , region } ) ;
106
110
107
111
// Initialize Proxy Config Server
108
112
portProxyConfig = await getPort ( ) ;
0 commit comments