Hello community, I am not able to access the public APIs like google static map api and also twilio/sendgrid from my lambda functions, however it is accessible from localhost, below is the error;
Error while calling google map api
2022-12-28T13:46:33.405Z adeec805-e3d9-4f5e-9a7e-c4b03fe1b17b ERROR weather_err: AxiosError: connect ETIMEDOUT 142.250.181.138:443
at Function.AxiosError.from (file:///var/task/node_modules/axios/lib/core/AxiosError.js:89:14)
at RedirectableRequest.handleRequestError (file:///var/task/node_modules/axios/lib/adapters/http.js:526:25)
at RedirectableRequest.emit (node:events:527:28)
at ClientRequest.eventHandlers.<computed> (/var/task/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
port: 443,
address: '142.250.181.138',
syscall: 'connect',
code: 'ETIMEDOUT',
errno: -110,
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [ 'xhr', 'http' ],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function], Blob: null },
validateStatus: [Function: validateStatus],
headers: AxiosHeaders {
Accept: 'application/json, text/plain, /',
'User-Agent': 'axios/1.2.1',
'Accept-Encoding': 'gzip, compress, deflate, br'
},
method: 'get',
url: 'https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998',
params: {
zoom: '12',
size: '400x400',
key: 'AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk'
},
data: undefined
},
request: <ref *1> Writable {
_writableState: WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
afterWriteTickInfo: null,
buffered: [],
bufferedIndex: 0,
allBuffers: true,
allNoop: true,
pendingcb: 0,
constructed: true,
prefinished: false,
errorEmitted: false,
emitClose: true,
autoDestroy: true,
errored: null,
closed: false,
closeEmitted: false,
[Symbol(kOnFinished)]: []
},
_events: [Object: null prototype] {
response: [Function: handleResponse],
error: [Function: handleRequestError],
socket: [Function: handleRequestSocket]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
maxRedirects: 21,
maxBodyLength: Infinity,
protocol: 'https:',
path: '/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk',
method: 'GET',
headers: [Object: null prototype],
agents: [Object],
auth: undefined,
beforeRedirect: [Function: dispatchBeforeRedirect],
beforeRedirects: [Object],
hostname: 'maps.googleapis.com',
port: '',
agent: undefined,
nativeProtocols: [Object],
pathname: '/maps/api/staticmap',
search: '?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk'
},
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'User-Agent: axios/1.2.1\r\n' +
'Accept-Encoding: gzip, compress, deflate, br\r\n' +
'Host: maps.googleapis.com\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk',
_ended: false,
res: null,
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'maps.googleapis.com',
protocol: 'https:',
_redirectable: [Circular *1],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
_currentUrl: 'https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=AIzaSyDvnSePX3KykgtV-i65AU59VXv0rQ6mKuk',
[Symbol(kCapture)]: false
},
cause: Error: connect ETIMEDOUT 142.250.181.138:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '142.250.181.138',
port: 443
}
}
I did a small change for testing, I remove custom vpc from serverless.yml file and it start working, now the paradigm shifted. I face the issue only when we apply lambda function in my custom VPC.