aws-sdk in node app after deploying does not start

449 views Asked by At

Im using NestJs and some AWS services from aws-sdk in docker , it works well locally, but when i deploy it in ec-2 instance on AWS have this error:

<--- Last few GCs --->

[18:0x55b3d70]    45648 ms: Mark-sweep 490.7 (494.0) -> 490.0 (493.7) MB, 6819.1 / 0.0 ms  (average mu = 0.082, current mu = 0.068) allocation failure scavenge might not succeed
[18:0x55b3d70]    47323 ms: Scavenge 490.8 (493.7) -> 490.3 (494.2) MB, 1141.9 / 0.0 ms  (average mu = 0.082, current mu = 0.068) allocation failure 
[18:0x55b3d70]    55666 ms: Mark-sweep 491.0 (494.2) -> 490.3 (494.0) MB, 8223.2 / 0.0 ms  (average mu = 0.141, current mu = 0.179) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x13da519]
Security context: 0x14a52a100921 <JSObject>
    1: checkTypeArgumentConstraints(aka checkTypeArgumentConstraints) [0x31cb38247d41] [/usr/src/app/node_modules/typescript/lib/typescript.js:~62294] [pc=0x131bf9dbd08a](this=0x3dcab4f004b9 <undefined>,0x371670384d41 <NodeObject map = 0x3baf228b0051>,0x235b39336099 <JSArray[2]>)
    2: checkSourceElementWorker(aka checkSourceElementWorker) [0x2a53971242e1] [/usr...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

I tried to upgrade node to last version in my instance, tried export node_options= --max-old-space-size=8192 in root of my project and in container, nothing helps. When i uninstal aws-sdk from package.json and deploy everything works. How to fix it.

1

There are 1 answers

1
Roman Karpyshyn On

The import method of service had to be changed. For example S3 instead

import { S3 } from 'aws-sdk';

you must use

import S3 = require("../../node_modules/aws-sdk/clients/s3");